0

For my app if I use finish() then it will close activity A. For the activity stack like A->B->C(currently visible) if I use finish() in C it will close C, not A or B and B resumes.

In such cases if I need to close all the activities at a glance by clicking a Close button in activity C then what is the solution ? Does Android provide any technique to achieve this ?


NOTE: I found a solution Here which is partially helpful, not enough to solve my problem. Though you may get some idea(s) from here.

Community
  • 1
  • 1
Soumyadip Das
  • 1,781
  • 3
  • 16
  • 34

2 Answers2

0

Refer this link it will help you

Finish all previous activities

Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

this will clear all the activities on top of home.

Community
  • 1
  • 1
Nirali
  • 13,571
  • 6
  • 40
  • 53
0

Ok, on close button click send a broadcast to your home activity then then call this :

// Inside broadcast recevier do this, it wont allow then write below code in a separate function and call this. 
Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
System.exit(0);

It will work surely, i have already done before and it is working for me.

Daud Arfin
  • 2,499
  • 1
  • 18
  • 37