我的应用具有还原功能,可以将当前数据库和设置替换为备份文件中的数据库和设置。
应用程序通过intent-filters对备份开放作出反应 我有一些代码来处理Activity onCreate方法
中的文件if (Intent.ACTION_VIEW.equals(intent.getAction())) {
String scheme = intent.getScheme();
// valid scheme are files or content in case of mail attachment
if (scheme.equals("file") || scheme.equals("content")) {
uri = getIntent().getData();
} else if (scheme.equals("http") || scheme.equals("https")) {
uri = getIntent().getData();
remoteUri = true;
}
// reset intent
setIntent(new Intent());
processURI(uri, remoteUri);
}
然后在我的processURI()函数中,我完成了所有工作,最后通过显示一个弹出窗口告诉用户应用程序现在将重新启动。 然后我调用system.exit(0);
它工作正常但是应用程序会在原始意图的同一个Activity上自动重新打开,即使我之前重置它...我怎么能避免这个?
答案 0 :(得分:0)
有关如何重新启动应用的信息,请参阅this answer。
来自链接的答案:
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(
getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
编辑:尝试;
getActivity().finish();
System.exit(0);
此外,调用recreate()
将重新启动当前活动。
请参阅this answer also。