如何给事件对强制关闭对话框的确定​​按钮对话框、按钮、事件

2023-09-06 21:59:31 作者:迷离的仙儿

您好我想知道,我该部队关闭对话框的确定​​按钮执行自己的操作?

Hi I want to know can I perform my own operations on Force Close 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);
  }
}