I have an application which starts a service when the widget is tapped.
This is the class for the widget:
public class PlayWidget extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; i++) {
int currentWidgetId = appWidgetIds[i];
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.playwidget);
views.setTextViewText(R.id.bLevelText, "My widget");
Intent intent = new Intent(context, PlayService.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pending = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.imageButton11, pending);
appWidgetManager.updateAppWidget(currentWidgetId, views);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i], R.id.imageButton11);
}
}
}
This is the manifest declaration for the Widget:
<receiver
android:name=".widget.PlayWidget"
android:icon="@drawable/play">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/playwidget_info" />
</receiver>
This is the manifest declaration for the Service:
<service android:name=".widget.PlayService"/>
The problem is that on Android 11, when the app is killed and i press the widget, the Service won't start anymore. Anyone has an idea on how can i fix this issue?