lon*_*ngi 5 android android-launcher
我有一个应用程序,如果从另一个应用程序启动(例如通过 Playstore),它会出现错误。它不会恢复到已经存在的实例Activity,而是作为新实例重新启动。
我拥有的:
launchMode="singleTop"声明每项活动manifest.xmllaunchMode=singleTask,但它具有相同的行为intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)在每个Intent开始新的内容时使用额外的ActivityonNewIntent()不在已经运行的实例中调用我使用以下代码从另一个应用程序启动我的应用程序(带或不带附加addFlag())
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("my.package.name");
launchIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(launchIntent);
Run Code Online (Sandbox Code Playgroud)
我的启动器活动是一个SplashScreenActivity,如果MainActivity用户使用以下代码登录并获取finished()
Intent intent = null;
intent = new Intent(SplashScreenActivity.this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
Run Code Online (Sandbox Code Playgroud)
我缺少什么?有什么建议欢迎留言!
经过更多研究后,我在SplashScreenAvtivity:onCreate()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!isTaskRoot())
{
String intentAction = getIntent().getAction();
if (getIntent().hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
finish();
return;
}
}
//...
Run Code Online (Sandbox Code Playgroud)
}
如果应用程序已经在运行,这将关闭 SplashScreenActivity。这适用于所有launch-modes
| 归档时间: |
|
| 查看次数: |
5283 次 |
| 最近记录: |