英文:
MainAcitivity Does not enter onNewIntent Method and call onCreate Again even it's SingleTask
问题
为了防止在点击深层链接后重新加载应用程序。我已经将启动页活动(SplashActivity)的启动模式设置为singleTask,并在onNewIntent方法中处理任何新的意图。
<activity
android:name=".activities.SplashActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.Splash">
</activity>
<activity
android:name=".activities.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait">
</activity>
另外,我将主活动(MainActivity)也设置为singleTask,以防止每次用户打开深层链接时重新加载。虽然启动页会顺利调用onNewIntent,但主活动每次都会重新创建,如何使MainActivity调用onNewIntent而不是onCreate呢?我尝试过在MainActivity的意图中添加标志FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP
,但这并没有起作用。
// SplashActivity
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Intent launchIntent = new Intent(this, MainActivity.class);
startActivity(launchIntent);
}
(以上内容是您提供的代码的翻译。)
英文:
to prevent the app from reload after clicking on deeplink. I have made the lunch mode for the splash activity singleTask and handled any new intent in onnewintent method
<activity
android:name=".activities.SplashActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.Splash">
</activity>
<activity
android:name=".activities.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
>
</activity>
also i made the maniActivity to be signleTask to prevent reload every time user open deeplink. the splash call onNewIntent smoothly but the mainactivity recreated every time how to make the MainActivity call onNewIntent instead of calling onCreate I have tried to add flags FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP
to MainActivity intent but it's not working
//splashActivty
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Intent launchIntent = new Intent(this, MainActivity.class);
startActivity(launchIntent);
}
答案1
得分: 0
你需要使用setIntent
,然后在onResume
中继续执行。
查看这个链接,我会说startActivity
可能是个问题。
英文:
You need to use setIntent
and then continue execution in onResume
.
Looking at this link I would say the startActivity might be a problem.
专注分享java语言的经验与见解,让所有开发者获益!
评论