Yograj Shinde
Yograj Shinde

Reputation: 839

Clear backstack of application in android on button click

I am developing app in which i want clear all my back-stack on click of log out button. i have searched and tried many solutions given but its not working for me. please if anyone can help me that would be appreciated.

i have tried following code on click of log out button

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

and also tried following code in manifest file

android:launchMode="singleTop"

Thank you in advanced

Thanx to all of you for your valuable reply

i have found one solution and tried this again was worked for me fine

Intent intent = new Intent(Settings.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
                Intent.FLAG_ACTIVITY_CLEAR_TASK |
                Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();

Upvotes: 0

Views: 842

Answers (2)

Deepak Jangir
Deepak Jangir

Reputation: 590

use in manifest android:noHistory="true"

Upvotes: 0

vipul mittal
vipul mittal

Reputation: 17401

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TASK);

above is working for me but Intent.FLAG_ACTIVITY_CLEAR_TASK is available from API 11

Upvotes: 3

Related Questions