Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1928870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T07:02:26+00:00 2026-05-17T07:02:26+00:00

I have two buttons on a widget that change some items in a widget,

  • 0

I have two buttons on a widget that change some items in a widget, if an orientation is changed on a phone, buttons do nothing. I read http://developer.android.com/guide/topics/resources/runtime-changes.html but this is all about activity not widget.

    @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) 
{
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);

    Intent active = new Intent(context, TvWidget.class);
    active.setAction(ACTION_WIDGET_RECEIVER);
    mDbHelper = new DbAdapter(context);
    fillChannelList(context, appWidgetIds[appWidgetIds.length-1]);
    Set<Integer> keys = channelsImages.keySet();
    Iterator<Integer> iter = keys.iterator();
    while(iter.hasNext())  
    {
        if(channelId == 0) 
        {
            channelId = iter.next();
            break;
        }
    }
    SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
    Editor edit = settings.edit();
    edit.putInt("channelId", channelId);
    edit.putInt("appWidgetIds", appWidgetIds[appWidgetIds.length-1]);
    edit.commit();
    active.putExtra("net.aerosoftware.tvvodic.appWidgetIds", appWidgetIds);
    PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
    remoteViews.setOnClickPendingIntent(R.id.button_next, actionPendingIntent);

    Intent refresh = new Intent(context, TvWidget.class);
    refresh.setAction(ACTION_WIDGET_REFRESH);
    refresh.putExtra("net.aerosoftware.tvvodic.appWidgetIds", appWidgetIds);
    PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refresh, 0);
    remoteViews.setOnClickPendingIntent(R.id.button_refresh, refreshPendingIntent);

    updateView(context);
    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T07:02:27+00:00Added an answer on May 17, 2026 at 7:02 am

    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.

    I would suggest something like the following:

    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);
            }
        }
    }
    

    Also have a look at this link: http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html

    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.

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an item swapper control consisting in two listboxes and some buttons
I have two buttons that increment and decrement a value by one with each
I've got a form where I have two radio buttons and two interchangeable controls
I have a UINavigationController. In its toolbar is a segmented control with two buttons.
I have two applications written in Java that communicate with each other using XML
I have a widget that displays a filesystem hierarchy for convenient browsing (basically a
I have two buttons set, OK and Cancel in main.xml. I have setOnclickListener for
I have two buttons, and need to link them with a line. I bind
I have two buttons: btnAdd and btnUpdate . I have written a jquery function
I wanted to have two buttons on the both end of Navigation Bar (in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.