views:

888

answers:

4

Hi,

For an unknown reason, I can't get my application leaving properly so that when I push the home button and the app icon again I resume where I was in the app.... But I would like to force the application to restart at the first activity... I suppose this has something to do with onDestroy() or maybe onPause() but I don't know what to do. thanks for any help.

+1  A: 

if you want to always start at the root you want to set android:clearTaskOnLaunch to true on your root activity

jqpubliq
yeah I tried that but then when i click the icon again it seems to call on Resume instead of onCreate...which means I get a screen without any of my methods starting
Sephy
A: 

After hard thinking and testing I finally got the right way of calling my activity to recreate when the app is left with the home button :

android:clearTaskOnLaunch in the manifest

+

onRestart(){ onCreate(); }

That does the trick...(better than when it is put in onResume which is called each time you launch the app, even the first time, causing a double display)

Sephy
That sounds bad. You should only need the `clearTaskOnLaunch` attribute. How are you launching your app in the first place? Directly from Eclipse using the ADT tools? If so, there was a bug that meant apps weren't being launched properly from Eclipse. It's since been fixed.
Christopher
yeah, directly from eclipse. but i tried with only clearTaskOnLaunch, and i coulnt get it to work...
Sephy
A: 

Does FLAG_ACTIVITY_CLEAR_TOP do what you need to do?

Intent i = new Intent(getBaseContext(), YourActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(i);
Bert
A: 

Here is an example to restart your app in a generic way by using the PackageManager (which works fine for me):

Intent i = getBaseContext().getPackageManager()
             .getLaunchIntentForPackage( getBaseContext().getPackageNam() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
Marc