tags:

views:

37

answers:

1

Hello,

Often when I open my Android app from either my Home screen shortcut or from the apps menu it restarts the main activity.

How can I prevent this behavior and make it bring the existing instance to the foreground if there is one running?

I've searched quite a bit to no avail. It would seem as though most others are not having this problem?

Thanks!

A: 

You can never assume that Android retains the state of your app after you move away from it - because of a low memory situation, it may have removed it from memory.

Your best bet is to store the current state (including the current activity) in your SharedPreferences, and in your main activity (the one marked as LAUNCHER in your manifest), you check the shared preferences and go to the activity marked there. You can also use the SharedPreferences to store other information about the activity, i.e. you can use it to fill out text fields and other things with whatever values they had when the user left.

EboMike