-1

hi i've read many posts on stackoverflow on the subject but i still am not able to solve the problem. i need to clear my activity stack but the following comand doest work:

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

i also tried the following for api 15 android4.0.3

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

noting seems to work.

here's the full method code

@Override
    public void onBackPressed() {
        super.onBackPressed();

        Intent intent = new Intent(this, FiltriAnagraficaPagina.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
    }
Pheonix7
  • 2,131
  • 5
  • 21
  • 38

3 Answers3

1

Try

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
softarn
  • 5,327
  • 3
  • 40
  • 54
0

this may help you

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
intent.addCategory(Intent.CATEGORY_HOME); 

//////////////////////////////////// edited as per your comment

as you start activity B
finish activity A
and on backpress of activity B
start activity A
vipin
  • 2,851
  • 4
  • 18
  • 32
  • http://stackoverflow.com/questions/6664189/androidwhat-is-difference-between-setflags-and-addflags-for-intent – vipin Apr 05 '12 at 12:55
  • it doesnt change anything...arggg i've tried many things but non work. im getting really desparate. is there any oter way? – Pheonix7 Apr 05 '12 at 12:59
  • i have given a link in comment please check that – vipin Apr 05 '12 at 13:00
  • ya i read it. (i was looking for that qustion also), but it still leaves me with the same problem. is there a way i can solve this with the androidmanifest.xml? – Pheonix7 Apr 05 '12 at 13:03
  • ok. i have say 2 activities A,B. A requests a webservie/db for data and activity B shows it. then when i press back i want to go back to activity A to make a new request. but what happens is that activity 2 is still running so when activity A does the request and wants to put the data in activity B it cant because it is already full. understand? – Pheonix7 Apr 05 '12 at 13:09
  • ok then you have two ways to implement this first finish a as you call b and in backpress of b call a with new data (2) use setresult – vipin Apr 05 '12 at 13:12
  • http://stackoverflow.com/questions/2679250/setresult-does-not-work-when-back-button-pressed – vipin Apr 05 '12 at 13:13
  • http://stackoverflow.com/questions/6564641/android-do-i-need-to-explicitly-setresult-to-result-canceled also this http://code.google.com/p/android/issues/detail?id=1671 – vipin Apr 05 '12 at 13:13
  • i doest really solve the problem. i tried just to see if it works, to just use 1 activity and to clear the activity stack and to recall the activity and it doent clean........:( – Pheonix7 Apr 05 '12 at 13:35
  • hey friend your question was how to clear activity stack to clear activity stack is something different then clearing activity your requirment can be fulfilled by my edited answer – vipin Apr 06 '12 at 04:59
  • http://stackoverflow.com/questions/5154743/android-clearing-the-full-activity-stack – vipin Apr 06 '12 at 05:07
0

Override onKeyDown() method instead of onBackPressed() in your Activity

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {


    if (keyCode == KeyEvent.KEYCODE_BACK) {

       Intent intent = new Intent(this, FiltriAnagraficaPagina.class);
           intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
           startActivity(intent);
        return true;
        }
     return super.onKeyDown(keyCode, event);
}
Ravi1187342
  • 1,247
  • 7
  • 14