How to clear all activities in Android app -


my app has many activities can called in order

example activity history: -> b -> c -> d -> -> b -> e

now in activity e, 'deregistering' device (logging user out, , deleting data might have downloaded sdcard). desire behavior app 'starts over' , user prompted login activity , hitting return user home screen.

so now, activity e should clear activity stack in way. currently, setting flag_activity_clear_top when launching a's intent e. problem is, when user had visited , gone intermediate activities , revisited before going e, there still activities on stack.

a -> b -> c -> d -> a

so user has been logged out , can't use activities b-d, if user hits activity a, can access activities b-d. there simple way have activities other login activity cleared stack?

update:

so i've tried updating baseactivity (each activity in app subclasses one) contain static flag isderegistering tells activity destroy if true. problem is, every activity calls finish(), , booted homescreen , cannot restart app until force closing app. there better way this?

i've figured out workable solution. following code goes baseactivity class.

    public boolean killifderegistering() {     if (isderegistering) {         log.d(tag, "deregistering true!");         if (getclass().getname().equals(loginactivity.class.getname())) {             //don't destroy activity, reset flag             log.d(tag, "stopping deregister process!");             isderegistering = false;         } else {             //finish activity             log.d(tag, "killing activity!");             finish();             return true;         }     }     return false; } 

using bit of reflection, can decide whether or not kill base activity, home launcher can restart app @ loginactivity. have make sure loginactivity not remain in stack after has performed login calling finish() on manually.


Comments

Popular posts from this blog

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -

openssl - Load PKCS#8 binary key into Ruby -