In my Application, activity A is launcher activity, from A it called B and from B it called C, I have such more than 5 activities. In C when I press home button, and again open my app it open C, that is fine in my case. But after pressing home button in C, when it idle for some time and application is killed, after that when I open my app it opens C. But I want to open main launcher activity that time. How can I do this?

and how do you assume that the app is getting killed? It does not happen just because your app is idle for sometime. If it has started from C means it was never killed. An application is automatically killed by the device only when the device is under load and dearth of memory
–
Vicky KapadiaSep 11 '12 at 6:09

4 Answers
4

Pressing the Home switches you from the app to the home screen, whilst
leaving your app running in the background.

Except that when your phone is running low on resources like memory it
will start to close apps that are running in the background, so that
your phone has enough resources for what you're trying to do now.
Games are often amongst the first apps the phone will "kill" to save
resources as they often use a lot more memory and CPU than other apps.
This is why sometimes your game is stil lrunning paused, and sometimes
Android has closed it for you.

on pressing home ,u have not finished activity it still exists in stack.only it goes to pause so use this.

if you are calling activity B from an activity A.and C from B

A->B

use startactivityforresult from A

and again B->C

use startactivityforresult from B

and when you want to exit from C then setResult(i.e. RESULT_OK) and finish C.and in OnActivityResult() in B,check if resultcode == RESULT_OK then again finish B and setresult(RESULT_OK) for A.same procedure will follow to finish A.

this will exit you from the application.and application will start from A not from C.

if your app is killed by the system i dont think it will start from c. If you are killing it through an task killer app then its a mistake. Force stop it from the app settings and then check.However if killed by task killer app and then from C if you get back to B and it is crashing then check for result code. if resultcode != RESULT_OK then you can handle your code here and save app from crash. if you have not started you activity for result then finish B and A before launching B and c.