startActivity 未保留 Intent extra
在我的应用程序崩溃后,我使用 Thread.setDefaultUncauhtExceptionHandler() 重新启动它。我想传递一个额外的意图,告诉它它刚刚死而复生,但它没有粘住。这是LockedUpActivity
的onCreate
。
public class LockedUpActivity extends Activity {
/** Called when the activity is first created. */
UncaughtExceptionHandler defaultHandler;
private static final String RECOVERED = "recovered";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setDefaultHandler();
if (getIntent().getBooleanExtra(RECOVERED, false)) {
Log.i("LockedUp", "Back from the dead!");
((TextView) findViewById(R.id.textview)).setText("Back from the dead!");
}
else {
Log.i("LockedUp", "Machiavelli in this..");
}
}
public void goDownInFlames(View v) {
startActivity(new Intent(this, GoingDownActivity.class));
}
private void setDefaultHandler() {
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Intent i = new Intent(getApplicationContext(), LockedUpActivity.class);
i.putExtra(RECOVERED, true);
startActivity(i);
defaultHandler.uncaughtException(thread, ex);
}
});
}
}
正如你所看到的,我正在设置额外的内容,但它绝不是“起死回生!”
I am re-launching my application after my it crashes using Thread.setDefaultUncauhtExceptionHandler()
. I would like to pass an intent extra telling it that it just came back from the dead, however its not sticking. Here is the onCreate
of LockedUpActivity
.
public class LockedUpActivity extends Activity {
/** Called when the activity is first created. */
UncaughtExceptionHandler defaultHandler;
private static final String RECOVERED = "recovered";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setDefaultHandler();
if (getIntent().getBooleanExtra(RECOVERED, false)) {
Log.i("LockedUp", "Back from the dead!");
((TextView) findViewById(R.id.textview)).setText("Back from the dead!");
}
else {
Log.i("LockedUp", "Machiavelli in this..");
}
}
public void goDownInFlames(View v) {
startActivity(new Intent(this, GoingDownActivity.class));
}
private void setDefaultHandler() {
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Intent i = new Intent(getApplicationContext(), LockedUpActivity.class);
i.putExtra(RECOVERED, true);
startActivity(i);
defaultHandler.uncaughtException(thread, ex);
}
});
}
}
As you can see, I am setting the extra, however it is never "Back from the dead!"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当应用程序崩溃或“强制停止”时,自动垃圾收集将完成,变量将被清除,应用程序的活动堆栈也会被清除。如果应用程序崩溃,附加内容将不会保留在那里。
When an Application crashes or is 'forced stop', automatic garbage collection is done, variables are cleared, and so is the activity stack of the app. The extras won't remain there if the app crashes.