2

I'm building an app that works on my Nexus 7 without any problems and also on my Galaxy S2. Now I've tested it on a Galaxy S3, but somehow the memory management is far more agressive. If I press the home button and wait a few minutes, OnCreate gets called again, so I assume the process has been killed. But if the process gets killed, for this particular application, I want it to start another activity.

I could use overriding onStop and onPause, but that would cause some unwanted behaviour, looking at the Activity Lifecycle. If the process isn't killed it is fine to return to the activity.

Is there a solution for this?

4

2 回答 2

2

By pressing the home button your activity can be destroyed if the system has determined it needs to free some resources.

This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

于 2013-04-19T11:35:47.947 回答
1

You can use savedInstanceState in your onCreate like this:

if( savedInstanceState != null ) {
            //Toast.makeText(this, savedInstanceState.getString("message")+"--> ", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(First.this, Second.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            return;
        }
于 2013-04-19T11:31:58.617 回答