I have a widget that supposed to call an Activity of the main app when the user clicks on widget body. My setup works for a single widget instance but for a second instance of the same widget the PendingIntent gets reused and as result the vital information that I'm sending as extra gets overwritten for the 1st instance. So I figured that I should pass widget ID as Intent
data however as soon as I add Intent#setData
I would see in the log that 2 separate Intents are appropriately fired but the Activity fails to pick it up so basically Activity will not come up and nothing happens (no error or warning ether)
Here's how the activity is setup in the Manifest:
<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>
And here's code that is setup for handling the click
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));
The main app and the widget are packaged as 2 separate APK each in its own package and Manifest
I think you need a <data>
tag in your <intent-filter>
in order for the intent you are firing to match the intent-filter you have registered.
https://developer.android.com/guide/topics/manifest/data-element.html
Also using Uri.EMPTY may be a problem. I'd create your own Uri scheme, so that your setData() call looks something like:
di.setData(Uri.withAppendedPath(Uri.parse("droidln://widget/id/"), String.valueOf(appWidgetId)));
and your intent-filter would look like:
<intent-filter>
<action android:name="bostone.android.search.RESULTS" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="droidln"/>
</intent-filter>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With