我有一个应用程序,如果从另一个应用程序启动(例如在Playstore上),则会出现异常.它不是恢复到已经存在的Activity,而是作为新实例重新启动.
我有的:
>在manifest.xml中使用launchMode =“ singletop”声明每个活动
>我使用launchMode = singleTask尝试了相同的 *** 作,但是它具有相同的行为
>在启动新活动的每个Intent上使用了额外的intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_top)
>在已运行的实例中不调用onNewIntent()
我使用以下代码从另一个应用程序启动我的应用程序(带有或不带有附加addFlag())
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("my.package.name");launchIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_top);startActivity(launchIntent);
我的Launcher-Activity是SplashScreenActivity,如果用户使用以下代码登录并启动finish(),它将启动MainActivity
Intent intent = null; intent = new Intent(SplashScreenActivity.this, HomeActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_top); startActivity(intent); finish();
我想念什么?欢迎任何建议!
解决方法:
请尝试将singleTask而不是singletop用于SplashScreenActivity.
依http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
“系统在新任务的根部创建活动并将其意图路由到该任务.但是,如果该活动的实例已经存在,则系统通过对其onNewIntent()方法的调用将该意图路由到现有实例.而不是创建一个新的.”
总结以上是内存溢出为你收集整理的Android:如果从另一个应用程序打开了一个应用程序,launchMode singleTop将不起作用全部内容,希望文章能够帮你解决Android:如果从另一个应用程序打开了一个应用程序,launchMode singleTop将不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)