Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK not working Android

Tags:

android

well, so, that´s my problem.

I need, when the user press the back bottom, to delete the stack of all activities opened:

@Override
public void onBackPressed(){
    Intent i = new Intent(context, CrisolMainApp.class);
    i.putExtra(CrisolMainApp.CERRAR_APP, true);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(i);
}

The point is that this is working with most of my phones, but yesterday I tried with a Samsung Galaxy Mini (android 2.3.3) and it is not working!! It is not deleting the stack of activities.

Anyone knows why?

EDIT: I was checking on doc, and I found out that the "Intent.FLAG_ACTIVITY_CLEAR_TASK" was added on API 11(my Samsung Galaxy Mini is working for Android 2.3.3, so, API 10).......I don´t know, but I guess that´s the problem.

Anyone knows how can I make it work the same way for API less than 11?

I was trying by adding these flags and it is not working either:

@Override
public void onBackPressed(){
    Intent a = new Intent(this, CrisolMainApp.class);
    a.putExtra(CrisolMainApp.CERRAR_APP, true);
    a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
    a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    a.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(a);
    finish();
}

and I also tried:

@Override
    public void onBackPressed(){
        Intent a = new Intent(this, CrisolMainApp.class);
        a.putExtra(CrisolMainApp.CERRAR_APP, true);
        a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        a.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(a);
        finish();
    }
like image 291
zapotec Avatar asked Jan 15 '13 15:01

zapotec


Video Answer


2 Answers

A simple fix should be adding the xml attribute android:noHistory="true" to all of your activities, which will mean that as soon as the user leaves that Activity, it will be gone, and no back stack will be stored

like image 181
Matt Taylor Avatar answered Dec 23 '22 14:12

Matt Taylor


You do not finish the activity.

Intent i = new Intent(context, CrisolMainApp.class);
i.putExtra(CrisolMainApp.CERRAR_APP, true);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
finish();
like image 43
Leandros Avatar answered Dec 23 '22 13:12

Leandros