My app is supposed to handle shared texts. For example URLs from the amazon app. So I added the following intent-filter to my main activity:
我的应用程序应该处理共享文本。例如亚马逊应用程序的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>
In my onCreate function of my activity, I'm processing the intent like so:
在我的活动的onCreate函数中,我正在处理这样的意图:
intent = getIntent();
if(intent.getAction() != null) {
if (intent.getAction().equals(Intent.ACTION_SEND)) {
if (intent.getType().equals("text/plain")) {
onNavigationDrawerItemSelected(1);
}
}
}
The problem is, that sometimes the onCreate function isn't called following a sharing action. I checked the onResume method, and indeed that's what is called. The problem is that the intents action isn't "ACTION_SEND", but is packagename.handled and doesn't contain the needed information.
问题是,有时在共享操作后不会调用onCreate函数。我检查了onResume方法,实际上这就是所谓的。问题是intents操作不是“ACTION_SEND”,而是packagename.handled,不包含所需的信息。
Why is that?
这是为什么?
1 个解决方案
#1
7
If your activity already exists, depending on Intent
flags and <activity>
attributes, that existing activity instance may be reused. Override onNewIntent()
to get the Intent
being delivered to an existing activity instance that is causing it to be brought back to the foreground. Look in there for your ACTION_SEND
values.
如果您的活动已存在,则根据Intent标志和
#1
7
If your activity already exists, depending on Intent
flags and <activity>
attributes, that existing activity instance may be reused. Override onNewIntent()
to get the Intent
being delivered to an existing activity instance that is causing it to be brought back to the foreground. Look in there for your ACTION_SEND
values.
如果您的活动已存在,则根据Intent标志和