Home > OS >  Android app widget didn't load data for specific Android 12 device
Android app widget didn't load data for specific Android 12 device

Time:09-07

I have implemented app widget option for my Android app which load the list of data from the app. However in Pixel 4 (Android 12) device it didn't load the data or is blank for the first time when I add the widget. After re-launching the app, then the list is appearing in the widget. Another thing is widget becomes blank when re-sized as well as re-located or change the widget screen.

On other Android (Android 12 or other versions) devices this works fine.

CodePudding user response:

Assign data to the widget only after making sure that you have received the data from the server. else show a proper error.

like below:

if(data != null){
   message.setText(data.getString);
}else{
  Toast.makeText(getApplicationContext(), "No data available", Toast.LENGTH_LONG).show(); } 
}

CodePudding user response:

I have added onAppWidgetOptionsChanged() function and in that I have updated the widget data. Now after relocation and resizing the widget do not get blank. However one problem remains and that is after creating the widget for the first time( without resizing) it is blank. But if I resize it then it shows the list.

override fun onAppWidgetOptionsChanged(
    context: Context,
    appWidgetManager: AppWidgetManager,
    appWidgetId: Int,
    newOptions: Bundle?
) {
    updateAppWidget(context, appWidgetManager, appWidgetId)
    super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions)
}
  • Related