如何在强制关闭对话框的确定​​按钮上发出事件

Aru*_*ole 2 android

嗨,我想知道我可以在Force Close Dialog的OK按钮上执行自己的操作吗?

And*_*lva 6

恐怕你不能这样做.但是你可以通过使用未捕获的异常处理程序来避免强制关闭.

这些链接可能会有所帮助.

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

上述链接中的示例代码段,

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);
  }
}
Run Code Online (Sandbox Code Playgroud)