4

I have got stuck in situation please help me .Here is the problem .I have a menu screen in my application.Now have given option to go back to menu to all screens that has not come directly from menu screen .For example I go to Activity B like Menu ->Activity A -->Activity B. Now I have written on pressing backtoMenu button.

this.finish();
startActivity(new Intent(SelectStateActivity.this,MenuScreen.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

I am not finishing Activity A because I want to be on activity A when I press back button on activity B.So it will be on stack when I press menu button on Activity B. I come to menu screen which is fine but when I press back on menu screen I come to Activity A.Which is not wanted.I also tried

this.finish();
startActivity(new Intent(SelectStateActivity.this,MenuScreen.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP));

and

  startActivity(new Intent(SelectStateActivity.this,MenuScreen.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK));

But haven't worked.Please help me.

Bansal_Sneha
  • 1,039
  • 12
  • 36

1 Answers1

1

You can solve the issue by following solution.

  1. Using normal observer pattern which is implemented using core java. for observer pattern refer this

  2. Or same pattern implemented in android which is Broadcast receiver. In this solution every activity is registered for your custom broadcast Massage and once you launch Menu activity broadcast that message so that registered activities which can listen message and finish itself.

Let me know if you have issue in above.

  • Your solution is acceptable but why clear_task and clear_top not working . – Bansal_Sneha Nov 19 '14 at 09:42
  • You can check the given link and refer the answer given by Darpan there :- http://stackoverflow.com/questions/4342761/how-do-you-use-intent-flag-activity-clear-top-to-clear-the-activity-stack. BTW if my solution helps you, you can accept or upvote it. – Tech_Intelliswift Nov 19 '14 at 09:50