简体   繁体   中英

How to relaunch application when app went to background to foreground in android?

In my application, i had wierd problem that when app goes background (press home button), then i should restart my app when it comes to foreground, Instead of getting previous state.

Can any one help me to sort out this.

EDIT:

i explain my problem clearly,I am having four Activities A1,A2,A3,A4.

A1 - ListActivity - loading events from server. A2 - SearchActivity A3- EventDetail page

See if i was currently in A3 then i went to background, when i come to forground i should display A1 (Again i have update data from server). Finally i want restart app.

Regards, Srinivas

Try to set in the manifest file for your homeActivity the "android:clearTaskOnLaunch" property to true. In this way when you press the home button, once the application is restarted it will display your homeActivity instead of the last started activity.

I do the same thing in an app I made. Basically I just used the onResume function that is called when the app comes into the foreground from the background to restart the activity. Just add that and restart the activity and your app will restart each time you load it (which I believe is what you want).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM