Reputation: 815
I have two Activities FirstActivity and SecondActivity.
FirstActivity has an intent filter MAIN, LAUNCHER and DEFAULT. SecondActivity is just a normal activity and no other flags is set in the AndroidManifest.
My application is C2DM enabled and when a notification is received a taskbar Icon is displayed and when clicked it opens SecondActivity.
Arrival of Notifications has two scenarios: First, My Application is Already Running when notification arrived and second My Application is totally not running.
On the first scenario, everything is fine. A notification is received, i clicked from the notification drop down and my SecondActivity is displayed. When I press back SecondActivity is finished and application goes to the background. When I start my application again from Recent Applications, it displays FirstActivity which is correct since its the MAIN, LAUNCHER and DEFAULT.
On the Second Scenario, A notification is received, I clicked it from the notification drop down and my SecondActivity is displayed. When I press back SecondActivity is finished and application goes to the background. When I start my application again from recent Applications, it displays SecondActivity which is wrong. I am expecting FirstActivity to be displayed because it should be a fresh start.
I tried ForceKilling the application after the second scenario but the result is the same, I needed to restart my phone to be able to start from FirstActivity Again.
Have you guys encountered the same problem? or is it just me? What do you think is wrong with my configuration?
I also tried setting noHistory=false to SecondActivity but still the results are the same.
Upvotes: 2
Views: 1648
Reputation: 71
It is the correct behavior.. if you start the application through "Recent Application" it will point from the last activity. Try launching it through normal application list
Upvotes: 1
Reputation: 156
When you start application from 'Recent Application' shortcut, it will launch the last activity. So you can try to launch the application from the application list, see whether it solves your problem.
Upvotes: 1
Reputation: 34301
you can call your second activity with the flag set no history like this,
intent1.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
This has worked for me several times.
Read from the Android Doc
Upvotes: 0
Reputation: 8242
In Second scenario i think activity stack is empty as app is closed . so now you are starting activity2 , means this is the only activity in stack . now desired back behavior can be possible by overriding onbackpress and start activity1 if its second scenario .
Upvotes: 0
Reputation: 9510
For your main Activity try to set the lauch mode as "singleInstance" in the AndroidManifest file. for second activity set "Finish On Task launch" to true.
Upvotes: 0