开发者

Intent extras not being preserved with startActivity

开发者 https://www.devze.com 2023-04-10 03:03 出处:网络
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

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, howev开发者_开发问答er it is never "Back from the dead!"


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消