恐怕你不能这样做.但是你可以通过使用未捕获的异常处理程序来避免强制关闭.
这些链接可能会有所帮助.
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)