我正在创建自己的UncaughtException行为。我想发送一封包含该报告的电子邮件,以便在处理UncaughtException时,我想创建一个选择器,让用户选择他们的电子邮件客户端。
当我这样做时,在调用Intent之后,我必须杀死进程。但是杀死进程会使Intent选择器被创建三次而不是一次。我该怎么办?
public class BaseActivity extends AppCompatActivity implements Thread.UncaughtExceptionHandler {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(this);
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
MyLog.w("[BaseActivity]::[uncaughtException]");
ex.printStackTrace();
StringWriter errors = new StringWriter();
ex.printStackTrace(new PrintWriter(errors));
final String message = errors.toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"my@email.address"});
intent.putExtra(Intent.EXTRA_SUBJECT, "ERROR: Controller");
intent.putExtra(Intent.EXTRA_TEXT, message);
try {
MyLog.i("[starting chooser]::[%s]",System.currentTimeMillis());
startActivity(Intent.createChooser(intent, getString(R.string.msg_send_action_msg)));
} catch (ActivityNotFoundException ex1) {
Toast.makeText(getApplicationContext(), R.string.msg_err_no_email_client, Toast.LENGTH_LONG).show();
}
android.os.Process.killProcess(android.os.Process.myPid());
}
}
答案 0 :(得分:0)
在finish()
startActivity