Android意图有时会"处理"而不是ACTION_SEND

Jos*_*ude 9 android action android-intent

我的应用程序应该处理共享文本.例如亚马逊应用程序的URL.所以我在主要活动中添加了以下intent-filter:

    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
    </intent-filter>
Run Code Online (Sandbox Code Playgroud)

在我的活动的onCreate函数中,我正在处理这样的意图:

        intent = getIntent();
        if(intent.getAction() != null) {
            if (intent.getAction().equals(Intent.ACTION_SEND)) {
                if (intent.getType().equals("text/plain")) {
                    onNavigationDrawerItemSelected(1);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

问题是,有时在共享操作之后不会调用onCreate函数.我检查了onResume方法,实际上这就是所谓的.问题是intents操作不是"ACTION_SEND",而是packagename.handled并且不包含所需的信息.

这是为什么?

Com*_*are 7

如果您的活动已存在,则根据Intent标志和<activity>属性,可以重用现有活动实例.重写onNewIntent()以将Intent正在传递到现有活动实例,从而使其返回到前台.在那里寻找你的ACTION_SEND价值观.

  • 在我的情况下,也不会调用onNewIntent()。 (2认同)