Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 leave the app, go to the android home screen or another application and then return to the mentioned arbitrary Activity directly by "starting" the application again.

But when I install the application on the phone directly by downloading the apk-file, I will always return to the root Activity of the application when I return to this app, after I switched to another application or the android home screen.

Does anybody know where this behavior comes from or how I can fix this issue?

UPDATE: I run the application on real hardware in both cases.

like image 496
ashiaka Avatar asked Dec 15 '22 16:12

ashiaka


2 Answers

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

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

}

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

like image 67
ashiaka Avatar answered Apr 09 '23 13:04

ashiaka


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

like image 29
Avadhani Y Avatar answered Apr 09 '23 15:04

Avadhani Y