Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app restarts when opened by clicking app icon

Scenario :

I open my app by clicking icon, do something, navigate through activities, pause the app by clicking home button.

Case 1:

If I open my app by clicking icon again, the app restarts from the first activity.

Case 2:

If I open my app from recently open apps (in 4.0 by pressing menu button and selecting my app) it starts from the paused state.

I want the behavior 2 always to occur, don't want my app to restart every time when it is opened by clicking icon.

I have compared my manifest file with other apps and they are similar to mine, but behave differently (i.e like 2nd case which i want).

Edit:

This has been asked here : App completely restarting when launched by icon press in launcher

but no answers :(

like image 983
sanjeev Avatar asked Jul 09 '13 10:07

sanjeev


People also ask

How do I stop apps from restarting on Android?

Option 1: Freeze Apps Open “Settings” > “Applications” > “Application Manager“. Choose the app you wish to freeze. Select “Turn off” or “Disable“.

When the app is launched after pressing the app icon which of these methods are called?

It will call the onResume() method if the app is already in the stack. And if the app not in the stack then it will call the onCreate() method. This mechanism is based on the launchMode specified for the activity.


1 Answers

I found it. I had set a flag android:launchMode="singleTask" in my activity flag. I deleted that code.

I also added onsaveInstance method to all the activities in my code and it's working now!

Thanks :)

like image 182
sanjeev Avatar answered Oct 08 '22 02:10

sanjeev