I google it but even if i run this code below it didnt finish the other activities.
ButtonClick.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
LoginManager.getInstance().ctrl = false;
UserManager.getInstance().loginControl();
OrderManager.getInstance().orderCtrl = false;
Intent intent = new Intent(OrderComplete.this,
MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
}
});
}
UPDATE Please refer to the other answers, I cannot delete the answer because it is marked as accepted
As per Our Discussion in Comments
Your Given Code is Fine !
Q1. Why its Not Finishing All the Activities ?
Ans. I think
All Activities Are Finished
Except Activities
who haveThread or AysncTask
running in Background or not Finished yet!Q2. How Can i Finish Them ?
Ans. Make Sure your Thread Should be Finished ! or
You can Try Timeout etc
!Additional
for this Add Code
Inside First Activity (Which is not to be Finished)
Try by Making
Object of Remaining Activities
to Finish Them !So Try code :
Try this it works fine with me
UPDATE
sorry I forget to give these lines. Put these line in onCreate() method of all Activities or if you have any base activity you can put it there , then no need to put in all activities.
UPDATE
So sorry forget one more thing to give put this class in your Base activity
To remove all the Activities while opening new one, then do the following