Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would suggest creating a Service (possibly subclassing this within your AppWidgetProvider) and overriding the onConfigurationChanged() method. Using the service will allow you to delegate your business logic to be handled by the service, build, and update your widget. It will also allow you to manage rotations. And if you're performing any blocking operations then the service would be a good place to spawn a Thread and return the result back to the main UI thread to avoid ANRs.</p> <p>I would suggest something like the following:</p> <pre><code>public class MyWidget extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { context.startService(new Intent(context, MyUpdateService.class)); } public static class MyUpdateService extends Service { @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); // Update the widget RemoteView remoteView = buildRemoteView(this); // Push update to homescreen pushUpdate(remoteView); // No more updates so stop the service and free resources stopSelf(); } public RemoteViews buildRemoteView(Context context) { RemoteView updateView = null; updateView = new RemoteViews(context.getPackageName(), R.layout.my_widget_layout); // Your code to build and update the remote view return updateView; } @Override public void onConfigurationChanged(Configuration newConfig) { int oldOrientation = this.getResources().getConfiguration().orientation; if(newConfig.orientation != oldOrientation) { // Update the widget RemoteView remoteView = buildRemoteView(this); // Push update to homescreen pushUpdate(remoteView); } } private void pushUpdate(RemoteView remoteView) { ComponentName myWidget = new ComponentName(this, MyWidget.class); AppWidgetManager manager = AppWidgetManager.getInstance(this); manager.updateAppWidget(myWidget, updateViews); } } } </code></pre> <p>Also have a look at this link: <a href="http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html" rel="noreferrer">http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html</a></p> <p>Also, be sure to indicate that you are interested in receiving notifications on rotation change within your manifest. Something like this will work: android:configChanges="keyboardHidden|orientation" declared within your service declaration inside the manifest.</p> <p>Hope that helps!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload