android - onNewIntent 没有被调用

标签 android android-intent start-activity

我已经通过调用启动 Activity 开始了一个新的 Activity 。但是在 Activity 启动后,方法 onNewIntent 中的 finish() 没有被调用!!.

WebActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
    if (intent.getStringExtra("url") != null) {
        Intent intent1 = new Intent(getBaseContext(), WebActivity.class);
        intent1.putExtra("url",intent.getStringExtra("url"));
        startActivity(intent1);
        finish();
    }
}

最佳答案

仅供引用

调试首先删除不需要的行

super.onNewIntent(intent);
setIntent(intent); 

调用 finish() Intent

Intent intent1 = new Intent(getBaseContext(), WebActivity.class);
intent1.putExtra("url",intent.getStringExtra("url"));
finish();
startActivity(intent1)

您也可以尝试使用 FLAG_ACTIVITY_NO_HISTORY .

If set, the new activity is not kept in the history stack. As soon as the user navigates away from it, the activity is finished. This may also be set with the noHistory attribute.

关于android - onNewIntent 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42197583/

相关文章:

android - 背景图像或背景颜色?

android - 即使 Activity 存在,ActivityNotFound

Android三个Activity,将数据从第三个Activity传递给父Activity

android - startActivity 和 startSubActivity

字段为空时的 Android 房间顺序

java - onTouchEvent 为多个指针返回相同的坐标

java - Holo 聚焦按钮可绘制的位置

android - 仅使用 BroadcastReceiver 时,是否有针对 FLAG_RECEIVER_REGISTERED_ONLY 的解决方法?

java - 将 boolean 值传递给上一个 Activity 并在 Android Java 中验证 boolean 值

java - 无法实例化应用程序 java.lang.RuntimeException :. ..BackupDB 无法转换为 android.app.Application