MainAcitivity Does not enter onNewIntent Method and call onCreate Again even it's SingleTask

huangapple 未分类评论47阅读模式
英文:

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

   &lt;activity
        android:name=&quot;.activities.SplashActivity&quot;
        android:label=&quot;@string/app_name&quot;
        android:launchMode=&quot;singleTask&quot;
        android:screenOrientation=&quot;portrait&quot;
        android:theme=&quot;@style/AppTheme.Splash&quot;&gt;

    &lt;/activity&gt;
    &lt;activity
        android:name=&quot;.activities.MainActivity&quot;
        android:label=&quot;@string/app_name&quot;
        android:launchMode=&quot;singleTask&quot;
        android:screenOrientation=&quot;portrait&quot;
       &gt;
    &lt;/activity&gt;

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.

huangapple
  • 本文由 发表于 2020年5月3日 20:54:46
  • 转载请务必保留本文链接:https://java.coder-hub.com/61574804.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定