如何以编程方式“重新启动”一个 Android 应用程序

我试图在我的应用程序中创建一个“注销”函数。基本上,通过注销,应用程序数据应该被清除。我想做的是登出后,应用程序应该重新启动,以便凭据等可以再次输入。我遇到的问题是,在用户点击“注销”的时候,应用程序已经运行了3-4个活动,我不确定如何返回这些活动。我如何(模拟?) 重启应用程序?

149026 次浏览

Checkout intent properties like no history , clear back stack 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);