如何给力事件关闭对话框确定按钮

时间:2011-07-26 07:31:31

标签: android

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

2 个答案:

答案 0 :(得分: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);
  }
}

答案 1 :(得分:2)

据我所知,无法在Android FC对话框中添加功能。但是,您可以做的是添加自己的uncaughtExceptionHandler来处理异常。但是,当您发现异常时,您可能会受到限制。您无法显示对话框(另请参阅this post原因)。