onNewIntent不叫 [英] onNewIntent is not called

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

问题描述

我有很奇怪的情况。结果
有一个应用程序,我决定创建第一个的code另一个。结果
我复制.xml文件,拷贝.java文件,使一切正常。结果
但是有一个很大的问题:我的 onNewIntent(意向意图)方法被调用的第一个项目,但它不是在第二个项目(称为code是一样的! )结果
结果的方法,这可能引发的话,但现在不能触发结果

I have very strange situation.
Having one app, I decided to create another one from the code of first one.
I copied .xml files, copied .java files so that everything is OK.
But there's one HUGE problem: my onNewIntent(Intent intent) method is called in first project, but it's not called in the second project (the code is the same!)

Method, which could trigger then, but can't trigger now

public void onClick(View arg0) {
            Intent browserInt = new Intent (Intent.ACTION_VIEW, 
                    Uri.parse("https://oauth.yandex.ru/authorize?response_type=token&client_id=zzzzz"));
            browserInt.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(browserInt);
        }

下面是onNewIntent()方法:

Here's onNewIntent() method:

@Override
protected void onNewIntent(Intent intent){
    System.out.println(" I WORKED!");
    Uri uri = intent.getData();
    if (uri!=null) {
        String m = uri.toString().split("#")[1];
        String[] args = m.split("&");
        String arg = args[0];
        String token = arg.split("=")[1];
        System.out.println(token);
    }

}

我看不到我的日志我的工作,很遗憾。
结果我读过很多关于这两个SO和在互联网上类似的问题,尝试设置意图标志SINGLE_TOP,SINGLE_TASK等。
结果这里的工作项目的Andr​​oid清单:结果

I don't see "I WORKED" in my logs, unfortunately.
I've read lots of similar questions both on SO and over the Internet, tried setting Intent flags SINGLE_TOP, SINGLE_TASK and so on.
Here's the Android Manifest of WORKING project:

 <application 
                android:name="yyy"
                android:icon="@drawable/yaru_icon"
                android:allowBackup="false"
                android:label="xxx"
                android:theme="@style/LightTheme">
        <activity
                android:name=".Main"
                android:label="xxx"
                android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
      </application>

我很绝望,为什么类似code不工作了吗?结果
搜索结果
修改我用尽了一切:SINGLE_TOP,SINGLE_INSTANCE,SINGLE_TASK ..结果
但后来我偶尔这样做的另一项活动:结果

I'm quite desperate, why the similar code is not working anymore?


I've tried everything: SINGLE_TOP, SINGLE_INSTANCE, SINGLE_TASK..
but then I occasionally did this on another activity:

    Main m = new Main();
    m.onNewIntent(this.getIntent());

和它终于成功了!结果
我不知道,它是否是一个肮脏的解决方法或错误,如果任何人都可以解释它,请评论。

And it finally worked!
I don't know, whether it's a dirty workaround or a bug, if anyone can explain it, please, comment.

推荐答案

您想收到onNewIntent()的活动应该有

The Activity you want to receive onNewIntent() in should have

android:launchMode="singleTop"

或添加标志TN意图

browserInt.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
                    Intent.FLAG_ACTIVITY_SINGLE_TOP);

作为<一个记录href=\"http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29\">onNewIntent(Intent)

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

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