What I am trying to say here is the problem I'm facing to relaunch my app from same state where it was left before. I have did lot of R&D on this and have gone through the questions posted in stackoverflow.So please it is not necessary to say that it is a duplicate.
I tried putting these options
objIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
while starting the activity. Also I have tried this,
objIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
And finally I tried this method also
objIntent.setAction(Intent.ACTION_MAIN);
objIntent.addCategory(Intent.CATEGORY_LAUNCHER);
But none of these seem to be working for me.
The scenario goes like this, where this fails.
I run my application, go to some activity from the initial activity say from A to B
Now I will press my phone home button and do some actions like clicking photo and etc.
Again I try to launch the app from home screen.
Oops!! Now my app has not retained its state, it is launching from the initial state.
Note:
However this is not true in all the cases. some times say around 1 or 2 times out of 10 or 15 times, it launches from the same state where it was left before.
One more doubt i have is do I need to set this for all the intents? Say i have some 10+ positions of Intent i.e., starting the activity. Do I need to add this piece of code in all those places? I included this for 2 or 3 cases
Update:
This works in the debug mode, but when it comes to the point of an apk create, it is getting failed. However, if I try number of times it gives me the required result and there after behaves in the way as expected. Breaking my head to understand why it happening like this.
Any one has the answer for this?