Anand Anand - 3 months ago 22
Android Question

Expire login session after some time in android

I need to implement auto log out functionality in my android application , no matter which screen is showing currently.

Thanks in advance!

Answer

Just set one alarm manager after login then whenever that alarm will trigger then call one broadcast reciver and in that broadcast just write code for log out and clear all session value which related to that login

u can restart your app like this and from this all previews activity all top will be also clear

Intent i = cntxt.getPackageManager().getLaunchIntentForPackage(cntxt.getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addCategory(Intent.CATEGORY_HOME);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
cntxt.startActivity(i);