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:
- register broadcast receiver in base activity class can call anywhere. in handler, call finish(), unwinding whatever stack may exist.
- use frowned-upon system.exit().
- 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
- call gettaskid () task id.
- obtain activitymanager object , call getrunningtasks list of running tasks (check out warning in doc, not understand clearly)
- when task in list match id above can activity in root using field baseactivity
Comments
Post a Comment