-5

I have 3 Activities A, B, and C.

A is the home activity and B is its child and C is its child.

When I go to Activity C and return to A by pressing back button it gets proper navigation. But after this, if I press back button again to exit the app, it goes back to Activity B instead of exiting the app.

I have finished the Activity B onBackpressed override.

And I have implemented dynamic fragments on Activity B is that causes this problem.

I can't find out why this happens. Does Anyone have an answer?

Samir Bhatt
  • 3,041
  • 2
  • 25
  • 39
Sayandh
  • 61
  • 1
  • 10

2 Answers2

1

You can use finish() or finishAffinity() to end that activity

@Override
public void onBackPressed() {
   finishAffinity();
}
ankita patel
  • 4,201
  • 1
  • 13
  • 28
Android Geek
  • 8,956
  • 2
  • 21
  • 35
0
B.b.finish();

Explanation : Declare this in B Activity :

private static B(classname) b(some name);

Call this in which class do you finish B Activity :

B.b.finish();
MinnuKaAnae
  • 1,646
  • 3
  • 23
  • 35
New
  • 152
  • 1
  • 2
  • 12