Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App always starts fresh from root activity instead of resuming background state (Known Bug)

I am facing exactly the problem mentioned in these links:

http://code.google.com/p/android/issues/detail?id=2373

http://groups.google.com/group/android-developers/browse_thread/thread/77aedf6c7daea2ae/da073056831fd8f3?#da073056831fd8f3

http://groups.google.com/group/android-developers/browse_thread/thread/2d88391190be3303?tvc=2

I have a simple root activity with the LAUNCHER and MAIN intents and nothing else. I start another activity with has no flags or anything extra in the manifest whatsoever.

I launch the app (root activity) and from there start the 2nd activity. On pressing the Home button the task goes to the background. On launching the app again (from Launcher or from holding the Home button for recent apps) it starts a new instance of the root activity on top of the existing stack.

If I press the back button, the new "root" activity closes and the old 2nd activity is visible, which means its launching the root activity in the same task instead of bring the task to the foreground.

To counter this I made the root activity's launch Mode singleTask. Now when I press home and launch the app again, it clears the activities above the old root task and brings the old root task to the foreground instead of just bringing the entire old task with the 2nd activity on top to the front. Note that the old root task still retains its application state, which means it wasn't a new instance, but the the higher activities had been killed.

It even occurs on other applications downloaded from the market. The manual install method has no effect for me, it still launches the same way.

like image 742
Monstieur Avatar asked Feb 17 '10 12:02

Monstieur


People also ask

Which method is called when app goes in background?

The onPause() and onResume() methods are called when the application is brought to the background and into the foreground again.


1 Answers

    @Override  protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {          // Activity was brought to front and not created,          // Thus finishing this will get us to the last viewed activity          finish();          return;      }       // Regular activity creation code...  }  
like image 180
Sachin Gurnani Avatar answered Oct 22 '22 23:10

Sachin Gurnani