android - how to finish all activities except the first activity? -


i google if run code below didnt finish 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 other answers, cannot delete answer because marked accepted

as per our discussion in comments

your given code fine !

q1. why not finishing activities ?

ans. think all activities finished except activities have thread or aysnctask running in background or not finished yet!

q2. how can finish them ?

ans. make sure thread should finished ! or you can try timeout etc !


additional

pass string intent  

for add code

intent.putextra("finishingallact", "yes"); 

inside first activity (which not finished)

try making object of remaining activities finish them !

so try code :

if(getintent().getstringextra("finishingallact")!=null) {  if(getintent().getstringextra("finishingallact").tolowercase().equals("yes"))   {     yourremainingact act1=new yourremainingact();     act1.finish();     // try same remaining activities    } } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -