My widget is working and directly going to the activity I put below. But when it comes to my Android 12, when I click my widget on the home screen it only runs the default starting activity that can see from the android manifest. How can I fix this? TIA
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
for (int appWidgetId : appWidgetIds) {
Intent intent = new Intent(context, SecondPage.class);
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
pendingIntent = PendingIntent.getActivity(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}else {
pendingIntent = PendingIntent.getActivity(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.thisWidget);
views.setOnClickPendingIntent(R.id.thisBtn, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
It's all good now. I just reset the data of the application from my android phone. I'm sorry though I had no option left because I was finding the problem for hours.