1

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

Srinivas
  • 1,688
  • 8
  • 30
  • 51
  • 2
    Whatever problem that you are trying to solve with this plan can be better solved some other way. For example, if you are crashing, fix the bug, because that crash will probably occur due to other symptoms (screen rotation, putting the device in a dock, etc.). – CommonsWare May 31 '11 at 13:52

2 Answers2

1

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.

e-cal
  • 1,661
  • 2
  • 20
  • 28
  • I need to relaunch app when i am coming from background to foreground . – Srinivas May 31 '11 at 14:04
  • Don't post questions as answers. Gain some rep and post this as a comment. – Vladimir Ivanov May 31 '11 at 14:04
  • It was like when i was in activity3 then i click home and went to background then when i come forground i shoud get homeActivity instead of Activity3. – Srinivas May 31 '11 at 14:05
  • @Vladimir: sorry, I did not find the comment button. @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. – e-cal May 31 '11 at 14:14
0

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).

DustinRiley
  • 555
  • 6
  • 15