机器人:将数据添加到意图未能加载活动
-
26-09-2019 - |
题
我有一个小部件,应该调用主应用程序的活动时在插件本体的用户点击。我的设置作品一个Widget实例,但对于相同的插件的的PendingIntent的第二个实例得到重用,并为导致生命信息的,我传送给作为额外的被覆盖的第一个实例。所以我想我应该,但是只要通过微件ID为Intent
数据我添加Intent#setData
我会在日志中看到,2个独立的意图适当地解雇,但活动不能把它捡起来所以基本活动不会拿出并没有任何反应(没有错误或警告醚)
这里的活动是如何在清单设置:
<activity android:name=".SearchResultsView"
android:label="@string/search_results"
<intent-filter>
<action android:name="bostone.android.search.RESULTS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
和这里的代码,设置用于处理点击
Intent di = new Intent("bostone.android.search.RESULTS");
di.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// if line below is commented out - the Activity will start
di.setData(ContentUris.withAppendedId(Uri.EMPTY, widgetId));
di.putExtra("URL", url);
views.setOnClickPendingIntent(R.id.widgetContent,
PendingIntent.getActivity(this, 0, di, 0));
在主应用程序和被包装插件作为2个独立的APK在其各自的封装和清单
解决方案
我觉得你需要在你的<data>
一个<intent-filter>
标签,以便您在烧结匹配您已注册的意图过滤器意图。
https://developer.android.com/guide/topics /manifest/data-element.html
另外使用Uri.EMPTY可能是一个问题。我想创建自己的URI方案,让您的使用setData()调用看起来是这样的:
di.setData(Uri.withAppendedPath(Uri.parse("droidln://widget/id/"), String.valueOf(appWidgetId)));
和你的意图过滤器将类似于:
<intent-filter>
<action android:name="bostone.android.search.RESULTS" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="droidln"/>
</intent-filter>
不隶属于 StackOverflow