Your problem is in following steps as I know from your question is 1. Create notification after boot complete 2. Main activity will call on start up 3. You pressed home button so main activity will be stopped but will not destroy 4.
You click on notification from status bar so your application will be resume so that you have already main activity in your back stack and notification will create new activity like you mentioned in your question NewNoteActivity activity will be push on back stack. SO at this step you have two activities in back stack 5. You pressed back button so that last activity will be destroy and your main activity will be resume But you want to go to homepage screen So the Your problem is in following steps as I know from your question is 1.
Create notification after boot complete 2. Main activity will call on start up 3. You pressed home button so main activity will be stopped but will not destroy 4. You click on notification from status bar so your application will be resume so that you have already main activity in your back stack and notification will create new activity like you mentioned in your question NewNoteActivity activity will be push on back stack.
SO at this step you have two activities in back stack 5. You pressed back button so that last activity will be destroy and your main activity will be resume But you want to open homepage activity when you pressed on back button from NewNoteActivity activity So the solution is that when you pressed back button from your NewNoteActivityactivity you start main activity again with Intent. FLAG_ACTIVITY_CLEAR_TOP flag so that your main activity will recreate and will receive onNewIntent() method so there you can get flag and you can finish main activity for example Override public void onBackPressed() { Intent I = new Intent(this, Main.
Class); i. PutExtra("exit", true); i. AddFlags(Intent.
FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); super.onBackPressed(); } Now you have to implement onNewIntent() method in your Main activity On back button pressed from NewNoteActivity activity your Main activity will call onNewIntent() method so in this method you have to fetch flag variable which is passed from NewNoteActivity activity. If you get flag and if it is true then just finish the Main activity so that you will get Home screen EDIT You are saying that you have any of the activity from A,B,or C is opened and you pressed back button so that this activity will be closed. If you have only one activity in stack at that time your application will be closed means you will get home screen.
But if you have more than one activity and you pressed back button you have at least one activity in stack and now you click on notification so that this will open a new activity associated with your notification so that this activity will be pushed on that on back stack. Now if you pressed back button your last activity which is associated with your notification will be closed if you have not modify onBackPressed() method in that activity and then it will check back stack if any activity in back stack so that activity will be resumed or if there is no activity in back stack then your application will be closed and you will get home screen.
Your problem is in following steps as I know from your question is 1. Create notification after boot complete 2. Main activity will call on start up 3. You pressed home button so main activity will be stopped but will not destroy 4.
You click on notification from status bar so your application will be resume so that you have already main activity in your back stack and notification will create new activity like you mentioned in your question NewNoteActivity activity will be push on back stack. SO at this step you have two activities in back stack 5. You pressed back button so that last activity will be destroy and your main activity will be resume But you want to go to homepage screen.
So the Your problem is in following steps as I know from your question is 1. Create notification after boot complete 2. Main activity will call on start up 3. You pressed home button so main activity will be stopped but will not destroy 4.
You click on notification from status bar so your application will be resume so that you have already main activity in your back stack and notification will create new activity like you mentioned in your question NewNoteActivity activity will be push on back stack.SO at this step you have two activities in back stack 5. You pressed back button so that last activity will be destroy and your main activity will be resume But you want to open homepage activity when you pressed on back button from NewNoteActivity activity. So the solution is that when you pressed back button from your NewNoteActivityactivity you start main activity again with Intent.
FLAG_ACTIVITY_CLEAR_TOP flag so that your main activity will recreate and will receive onNewIntent() method so there you can get flag and you can finish main activity for example @Override public void onBackPressed() { Intent I = new Intent(this, Main. Class); i. PutExtra("exit", true); i.
AddFlags(Intent. FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); super.onBackPressed(); } Now you have to implement onNewIntent() method in your Main activity On back button pressed from NewNoteActivity activity your Main activity will call onNewIntent() method so in this method you have to fetch flag variable which is passed from NewNoteActivity activity. If you get flag and if it is true then just finish the Main activity so that you will get Home screen.
EDIT You are saying that you have any of the activity from A,B,or C is opened and you pressed back button so that this activity will be closed. If you have only one activity in stack at that time your application will be closed means you will get home screen. But if you have more than one activity and you pressed back button you have at least one activity in stack and now you click on notification so that this will open a new activity associated with your notification so that this activity will be pushed on that on back stack.
Now if you pressed back button your last activity which is associated with your notification will be closed if you have not modify onBackPressed() method in that activity and then it will check back stack if any activity in back stack so that activity will be resumed or if there is no activity in back stack then your application will be closed and you will get home screen.
Almost that... The thing is, I don't have a homepage activity, you misunderstood me. What I meant was that I wanted to go back to the home screen, the desktop, where you have all your widgets with a wallpaper... – Ricardo Amaral Sep 30 at 19:45 I had edit my answer now you can check it. – Dharmendra Sep 30 at 20:10 That seems like it could work but it also looks like a dirty hack.
All you said makes sense but I'm not happy with such solution and I'm not gonna use it. But I believe it works and solves the problem, so I'm marking it as accepted answer. – Ricardo Amaral Sep 30 at 20:20 Actually there is no any way to destroy one activity from another activity so if we want to do this some time we have to put out tricks weather we know that it is not perfect.
I think you have to remove flag from notification for FLAG_ACTIVITY_NEW_TASK If you will not get onNewIntent() Thanks. – Dharmendra Sep 30 at 20:44 I was actually going to implement your solution but then I realized it doesn't work exactly as I want it. In your example above you use Main.
Class, what if the stack top activity is other than "Main"? Let's say I have activities A, B and C. If any of these activities are opened and I press the back-button and then I click the notification and I press the back-button again, I don't know which of the A, B and C activities was opened to apply the workaround you posted.
Any other solution? How would you solve this problem? – Ricardo Amaral Sep 307 at 18:43.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.