How to "restart" an Android application

I am trying to create a "logout" function in my application. In principle, upon exiting the system, application data should be cleared. I would like to do this after logging out, the application must restart in order to re-enter credentials, etc. The problem that I am facing is that at the moment the user clicks "log off" in the application 3-4 actions are already running, and I'm not sure how to step over them. How can I (simulate?) Restart the application?

+46
android
Mar 22 '13 at 7:03
source share
2 answers

try using the lines below to restart the application

Intent i = getBaseContext().getPackageManager() .getLaunchIntentForPackage( getBaseContext().getPackageName() ); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); 
+143
Mar 22 '13 at 7:17
source share

Installation properties, such as history, stack clearing, etc. Intent.setFlags

 Intent mStartActivity = new Intent(HomeActivity.this, SplashScreen.class); int mPendingIntentId = 123456; PendingIntent mPendingIntent = PendingIntent.getActivity(HomeActivity.this, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) HomeActivity.this.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent); System.exit(0); 
+22
Mar 22 '13 at 7:16
source share



All Articles