I have an app with a home widget. I use PendingIntent
for clicked buttons on it, like so:
Intent intent = new Intent("MY_STRING_ACTION");
PendingIntent pendingIntent = PendingIntent.getBroadcast(appContext, 123, intent, PendingIntent.FLAG_CANCEL_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.my_btn, pendingIntent);
And I receive this intent action in a BroadcastReceiver
where I manage it. This works perfectly ONLY till Android 7.1. Due to Android 8 changes about BroadcastReceiver
I don't know how to correctly register this broadcast receiver (can't context register it because if activity is destroyed, is's automatically unregistred).
Right now my received is declared in manifest like so:
<receiver android:name="view.widget.WidgetActionsReceiver">
<intent-filter>
<action android:name="MY_STRING_ACTION" />
</intent-filter>
</receiver>