开发者

Android app activity always restarts

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 ma开发者_JS百科ke 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜