android - Clearing activity stack when you have multiple entry point activities? -


i have app has multiple entry point activities. want able clear activity stack programmatically. imagine app requires user authentication, , user wants invalidate session remotely (stolen device, example).

in case app has single starting activity, use:

intent intent = new intent(context, loginactivity.class); intent.addflags(intent.flag_activity_clear_top); startactivity(intent); 

to root activity. app may have been launched different entry points, , there might different activity classes @ root of stack.

some options:

  1. register broadcast receiver in base activity class can call anywhere. in handler, call finish(), unwinding whatever stack may exist.
  2. use frowned-upon system.exit().
  3. in above example, use intent.flag_activity_clear_task in addition other 2 flags (but available in api 11 , above...)

thanks

you can check name of activity @ root of task stack , start activity flag_activity_clear_top. if root activity not activity want start activity want in oncreate , call finish().
can find name of root activity

  1. call gettaskid () task id.
  2. obtain activitymanager object , call getrunningtasks list of running tasks (check out warning in doc, not understand clearly)
  3. when task in list match id above can activity in root using field baseactivity

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -