私はThread.setDefaultExceptionHandler()を使用して新しいアクティビティを開始しようとしています。しかし、ActivityManagerは起動直後に新しいアプリケーションプロセスを強制終了しているようです。Android uncaughtExceptionの後、ActivityManagerは新しいプロセスで強制停止します
私は多くの実験を試みました。
public void handleUncaughtException (Thread thread, Throwable e)
{
Intent intent = new Intent (getBaseContext(), RestartActivity.class);
intent.addFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pending =
PendingIntent.getActivity (getBaseContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
try {
pending.send();
}
catch (PendingIntent.CanceledException e1) {
logE ("send pending intent:" + e1); // logE is a wrapper for Log.e().
}
System.exit (1);
}
この場合、RestartActivityが開始され、表示されますが、1秒間だけ表示されます。その後、アプリは完全になくなり、Androidには以前のアプリが表示されます。
05-29 22:46:28.429 1465-3665/? I/ActivityManager: Force stopping com.perinote.crashtest appid=10170 user=0: from pid 14484
05-29 22:46:28.429 1465-3665/? I/ActivityManager: Killing 14486:com.perinote.crashtest/u0a170 (adj 0): stop com.perinote.crashtest
私もこの変形では、AlarmManagerを使って試してみた:
ログファイルは、この(PIDは若干異なります注意してください)が含まれ
public void handleUncaughtException (Thread thread, Throwable e)
{
Intent intent = new Intent (getBaseContext(), RestartActivity.class);
intent.addFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pending =
PendingIntent.getActivity (getBaseContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarm = (AlarmManager)getSystemService (Context.ALARM_SERVICE);
alarm.set (AlarmManager.RTC, System.currentTimeMillis() + 3000, pending);
System.exit (1);
}
この場合、RestartActivityはdoesnのまったく表示されず、logcatに次のような行が表示されます。
05-29 22:06:46.841 1465-11842/? I/ActivityManager: Force stopping com.perinote.crashtest appid=10170 user=0: from pid 12551
原因とはgのAndroidはすぐに開始されたプロセスを殺すために非常に悪いですか?
** android.os.Process.killProcess **を試しましたか? –
そうは思いませんが、それはしばらくしています。これは現在私の優先順位リストには載っていないので、何かを試す前に「中」の時間がかかります。ありがとう。 –
** System.exit(1)**は使用しないでください。タスクスタックをクリーンアップしないので、OSにアプリケーションを正常に終了させる機会はありません。タスクスタックの詳細はこちら:https://developer.android.com/guide/components/activities/tasks-and-back-stack.html –