如何以编程方式“重新启动" Android应用程序 [英] How to 'restart' an android application programmatically
问题描述
我正在尝试在我的应用程序中创建一个注销"功能.基本上,通过注销,应清除应用程序数据.我想做的是注销后,应用程序应该重新启动,以便可以再次输入凭据等.我遇到的问题是,在用户单击注销"时,该应用程序已经在运行3-4个活动,而我不确定如何退回它们.如何(模拟?)重新启动应用程序?
I'm trying to create a 'log out' function within my application. Basically, by logging out, the application data should be cleared. What I would like to do is after logging out, the application should restart so that credentials etc. can be entered again. The problem I'm having is that at the point of the user clicking 'log-out', the application already has 3-4 activities running, and I'm not sure how to step back through them. How do I (simulate?) a restart of the app?
推荐答案
签出intent属性,如无历史记录,清除堆栈等... Intent.setFlags
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);
这篇关于如何以编程方式“重新启动" Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!