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();
}
});
}
To clear top activities from stack use below code
It will delete all activities from stack either asynctask run or not in the application.
It works fine and also a good approach
when your going from one activity to other activity call finish();
do like this
call finish() after startactivity(...), so that A activity ll removed from the stack. when you press back button A activity ll be not there in stack.
1.If we haven't the asynctask class or thread in our class then by simply
write this code,can easily remove all activities from stack
2.this can also be done by making launcher activity as single task this can be done by changes in manifest file. as
3.But if we have asynctask in our app and also use of thread then both above methods fail..
for that we have to finish activity one by one
for eg. We have four activities A,B,C,D and each class has async task
and we have to go from A -> B-> C-> D
and from D We have again come back to *"A" and after pressing back button of device the app should be finish or can say exit*
For that we have to make static object of activities of all classes. Like
Do this in all classes B,C
And then in D
By pressing a button finish the objects of all classes Like
**mButton.setOnClickListener(new OnClickListener() {
Thats solve...
I know its not a gud way but also not a bad one...And main thing is its working :)
just remove every activity from stack except your first activity
or you can use the Activity Single top. for that you can use:
We can Use :
remove android:lanchMode="singleTop" from menifest and use setFlag
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);