onNewIntent不会被调用 [英] onNewIntent not get called

查看:697
本文介绍了onNewIntent不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过调用start活动来开始了自己的新活动.但是开始活动后,在方法onNewIntent中不会调用finish() !!

I have started a new activity of itself by calling start activity. But after the activity get started, in the method onNewIntent the finish() is not get called!!.

WebActivity.java

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();
    }
}

推荐答案

这是因为未调用onNewIntent !!!

It is because of the onNewIntent is not being called!!!

我把它放在调用此活动的地方.

I put this on where this activity is get called.

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);

然后它的工作就像一种魅力!!

then its works like a charm!!.

这是因为调用了新活动.而 FLAG_ACTIVITY_SINGLE_TOP 会使onNewIntent被调用.此 FLAG_ACTIVITY_SINGLE_TOP 不会启动新的活动.

It is because of calling new activity. And FLAG_ACTIVITY_SINGLE_TOP makes onNewIntent get called. This FLAG_ACTIVITY_SINGLE_TOP will not start a new Activity.

这篇关于onNewIntent不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆