android - How to use "Intent.FLAG_ACTIVITY_CLEAR_TASK" on pre-honeycomb devices? -


background

i need start activity on events (like notification click, can other event, broadcastreceiver) close other activities if running, or @ least don't give focus them.

for this, use intent.flag_activity_clear_task flag.

the problem

it seems intent.flag_activity_clear_task flag works on api 11 (honeycomb) , above .

some websites have claims intentcompat , there documentation says :

this flag obeyed on devices supporting api 11 or higher.

sadly can't find examples of using intentcompat functions, , descriptions vague , confusing intents flags documentations

the question

how can overcome problem?

should add localbroadcastmanager each of activities listen event, , close in case occurs ?

maybe i'm missing here? other functions shown on intentcompat class ? maybe 1 of them this?

please help.


edit: seems intent.flag_activity_multiple_task job of not-focusing on previous activities, documentation has vague description of how works, , has lot of warnings .

what i've noticed if close new activity, previous task of app won't take focus, go user has visited before.

does know how flag works, , should know it? safe used in such cases ?

if won't find other solution, think add answer.

you can use

       intent.addflag(intent.flag_activity_no_history |             intent.flag_activity_exclude_from_recents); 

or use broadcastreciver in of activities..

  public class myactivity extends activity {      private finishreceiver finishreceiver;    @override   protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     finishreceiver = new finishreceiver();     registerreceiver(finishreceiver,             intentfilter.create("finish", "xyz"));   }    @override   protected void ondestroy() {     super.ondestroy();     unregisterreceiver(finishreceiver);   }     private final class finishreceiver extends broadcastreceiver {      @override     public void onreceive(context context, intent intent) {         finish();     }   }  } 

for clearing stack:

           intent intent = new intent("finish");            intent.settype("xyz");            sendbroadcast(intent); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -