0

I am using ActivityGroup in my application, structure is as follow A > B > C (where A display first), and B and C makes a loop, like B > C > B > C > B and at both B and C if a user press back button, activity A should be display(even if user is on C), and there no need of B and C in stack.

So how can I implement onBackPressed() or any other method to make my application.

Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186

2 Answers2

0

You will need to use onBackPressed()

If A is a common activity it would be better if you moved it to the menu.

Ravi Vyas
  • 12,212
  • 6
  • 31
  • 47
0

If I would go into such situation then here is what I opt

  1. A activity is created and A will either call A or B
  2. Then B and C cycle in a manner when ever I create C from B or vice versa the calling activity must finish itself
  3. Finally On any activity whether B or C when back key is pressed it will destroy itself

for over riding back key in B and C activity here is code

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK))
    {
        finish();
    }
    return super.onKeyDown(keyCode, event);
}
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81