androidandroid-widgetandroid-anr-dialog

Is it possible to call appWidgetManager.updateAppWidget() in worker thread?


Hello? I'm making an android app widget.

There are many data related ui from DB in my widget.

So to avoid Broadcast Receiver ANR Issue, I made a remoteView and loaded data from db and set the data related ui in the remoteView.

Finally I called appWidgetManager.updateAppWidget(appWidgetId, remoteViews), and app widget were updated correctly.

But, I remember that UI update related logic must be in UI thread.

So, I wonder that can I still call appWidgetManager.updateAppWidget() in worker thread?


Solution

  • I remember that UI update related logic must be in UI thread.

    Correct, but your code has nothing to do with an UI in your app.

    I wonder that can I still call appWidgetManager.updateAppWidget() in worker thread?

    A RemoteViews is a data structure that describes a UI that another process will render. You are welcome to create such a data structure and hand it to the OS on a background thread. That other process will wind up using its main application thread for rendering the UI that is described by your RemoteViews.