appWidget Orientation Code

I have code in an appwidget that I want to run when the phone's orientation changes on the home screen, ie like when the keyboard flips out. I have an image that I want to change in an imageview in my appwidget. I can't use different layouts linked to the orientation (ie "layout" and "layout-land") because I don't know the name of the image file until runtime, it is created at runtime. Is there anyway to trigger code to run only if the home screen is shown, my appwidget is active and the orientation just changed?

I could listen for a configuration_change broadcast but that will run everytime the phone switches to landscape or portrait and I only want it to happen when the homescreen is shown. I cannot think of any good way in android to do this. Thanks


Asked by: Ada128 | Posted: 24-01-2022

Answer 1

There isn't a good way of doing this for images generated at runtime.

One approach would be to build both versions of the image and have two ImageViews that are visible depending on the layout/layout-land being used. (So the RemoteViews would update both ImageViews, but only the correct one would be visible.)

Answered by: Jack410 | Posted: 25-02-2022

Answer 2

Jeff, what is the reason for this limitation ? I would love to be able to use images generated at runtime, or construct the RemoteView on the runtime as well, rather than use the precompiled XML - this is so inflexible.

Answered by: Joyce218 | Posted: 25-02-2022

Answer 3

There is more info at

Basically update the widget from onConfigurationChanged() in an Activity and add android:configChanges="orientation" for that Activity in your manifest. Bad thing is, this doesn't cover all use cases.

Answered by: Agata333 | Posted: 25-02-2022

Similar questions

android - AppWidget Screen Orientation

Here is my question. I have an appwidget which works perfectly in a portrait screen orientation. However, When i changed my screen orientation to landscape my appWidget's width and height changing automatically by the home screen launcher and the problem is in landscape mode my widget's height is not set properly by the homescreen launcher. So, I need to detect is screen orientation changed and re-size my appwidget. I've g...

Android AppWidget on orientation changed

I understand my question sounds old and I did search a lot on SO but could not figure out how to solve it. I created an App Widget with a Refresh button which allow user to load information from Internet. Whenever user click Refresh, the widget will execute an Asynctask to download information. @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { ...

Android Screen orientation, shake cellphone crashes the application

I am having search application, which loads data retreived from the webservice. While application on create it shows progress dialog once its done with loading data it dismiss the progress dialog. problem is while loading if i change the orientation of the phone it works fine it try to load activity again, but if i start shaking the cellphone while it is loading data application get crashed, any solution ??...

android - From WebView Errors to ImageView Cover-ups to Screen Orientation

It all started with a simple WebView within an Android app. This view loads info from a public URL. Nothing unusual there. However ... if there should be a network interruption, you can easily end up with an error displayed prominently in the WebView. Well, that's no good, right? So I searched the docs and elsewhere for a way to suppress this, or trap it ... and fou...

Android TimePicker hour field disappears after orientation change

I am using a TimePicker under API 1.5 and when the orientation is changed on my device (a stock G1 running 1.6 - though NOT on the 1.5/1.6 emulator), the hour field goes blank. It still remembers the hour, it just doesn't show it. Is there any workaround for this? The same problem was described by someone else here:

Android Bluetooth crashes after orientation change

My code is based on the BluetoothChat sample from the API. I connect to another device just fine and I can read and write to the connection no problem. But then if I turn the device the orientation of the UI changes automatically. After this, if I try to write to the Bluetooth connection, my application crashes! It seems weird that the orientation of the screen somehow affects the Bluetooth. I am new to Android, an...

android - How to change orientation of xml "layout" area in Eclipse

The xml files that contains the Activity layouts can be rendered by Eclipse. How do I get that Eclipse screen area to have vertical orientation, not horizontal (inside Eclipse - it correctly shows as vertical in the emulator)? Peter

Android - Forced locale reset on orientation changes

I try to force the locale in my app to one the user specified. As this may be used to demonstrations, I want to change the language/locale in the app and not anytime for the whole device. I looked around SO and tried to use every hint I found here. The result: I can restart my test activity with the new language, but if I change the orientation, the locale will always be reseted to the device one. I

How can the landscape screen orientation be restricted in android?

How can the landscape screen orientation be restricted in android?

Problem saving WebView scroll position during orientation change in Android 2.1

I have a problem preserving the current scroll position of content loaded in Android's WebView control during orientation changes. The issue currently exist only in Android 2.1 and Android 2.1 Update 1 The code that I use is based on the default Browser application and looks like this: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mWebView = n...

android - How to detect orientation change in home screen widget?

I am writing a home screen widget and want to update the home screen widget when the device orientation changes from portrait to landscape or the other way. How can I make it? Currently, I tried to reigster to CONFIGURATION_CHANGED action like the code below, but the Android didn't allow me to do that by saying "IntentReceiver components are not allowed to register to receive intents". Can someone help me? Thanks.

android - Gracefully handling screen orientation change during activity start

I'm trying to find a way to properly handle setting up an activity where its orientation is determined from data in the intent that launched it. This is for a game where the user can choose levels, some of which are int portrait orientation and some are landscape orientation. The problem I'm facing is that setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) doesn't take effect until the activity...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android