Skip to content Skip to sidebar Skip to footer

How Can I Make An Android App Stop Restarting Every Time It Is Opened?

I developed a small android application and recently discovered a strange behavior. When I navigate to an arbitrary Activity after installing this app using usb and eclipse I can l

Solution 1:

putting the following code to the root Activity fixed this issue finally.

@OverrideprotectedvoidonCreate(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; 
    } 

}

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

Solution 2:

place in your manifest file android:launchMode="standard" for that particular activity for which you want to display only once.

Solution 3:

This is because of the way the system handles the application.

It is entirely upto the system to destroy your application upon the needs of other applications.

When you run it on your emulator, it does not destroy your application and hence, you resume from the same Activity you left.

But when you run it on your device, the device might feel that the memory occupied by the application needs to be freed up, and hence destroys the application. And the next time you start, it starts it from the beginning.

Post a Comment for "How Can I Make An Android App Stop Restarting Every Time It Is Opened?"