开发者

How to give event on force close dialog's ok button

Hi I want to know can I perform my own operations on Force Close 开发者_C百科Dialog's OK Button ?


I am afraid you can't do that. But rather you can avoid force close by using uncaught Exception handler.

These links might be helpful.

http://www.java2s.com/Open-Source/Android/File/android-daisy3-reader/org/geometerplus/zlibrary/ui/android/library/UncaughtExceptionHandler.java.htm

http://developer.android.com/reference/java/lang/Thread.UncaughtExceptionHandler.html

A sample snippet from the above link,

public class UncaughtExceptionHandler implements java.lang.Thread.UncaughtExceptionHandler {
  private final Context myContext;

  public UncaughtExceptionHandler(Context context) {
    myContext = context;
  }

  public void uncaughtException(Thread thread, Throwable exception) {
    StringWriter stackTrace = new StringWriter();
    exception.printStackTrace(new PrintWriter(stackTrace));
    System.err.println(stackTrace);

    Intent intent = new Intent(myContext, BugReportActivity.class);
    intent.putExtra(BugReportActivity.STACKTRACE, stackTrace.toString());
    myContext.startActivity(intent);

    Process.killProcess(Process.myPid());
    System.exit(10);
  }
}


As far as I know, it is not possible to add functionality to the Android FC dialog. But, what you can do is add your own uncaughtExceptionHandler to handle exceptions. However, when you catch an exception you are a bit limited to what you can do. You cannot show a dialog (see also this post why this is).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜