Skip to content Skip to sidebar Skip to footer

Appwidget Keeps Reseting Background To Transparent

I created functionality in an appwidget that allows a user to change the background from transparent to semi-transparent. The default is set to transparent in the xml. When the use

Solution 1:

Well, I actually found a way to reproduce it. I have an LG with a slide out keyboard, which rotates the home screen when you slide out the keyboard. Once it does that the semi transparent background disappears. It looks like I have to detect some kind of redraw event.

I found a work around, or solution, not entirely sure. Either way it solves the problem, at least when I test it with the above mentioned method of reproducing.

I implement a service that I keep running permanently, which overrides onConfigurationChanged() method.

For ideas see:

you can not receive this through components declared in manifests

This provides solutions for activities, but I am not sure yet how to use something like that in appwidgets, if at all possible:

Code sample, this service is started in the AppWidgetProvider class in the onEnabled() method. So it's only run once regardless of how many instances of your appwidget are running and should ideally be able to deal with any instance.

public class ExampleConfigChangeService extends Service
{
  @Override
  public void onCreate()
  {
    super.onCreate();
    /* whatever code you need here */
  }

@Override
  public void onStart(Intent intent, int startId)
  {
    super.onStart(intent, startId);
    /* whatever code you need here */
  }

/* you need this or it will not compile **/
  @Override
  public IBinder onBind(Intent intent)
  {
    /* We don't need to bind to this service */
    return null;
  }

@Override
  public void onConfigurationChanged(Configuration newConfig)
  {
    /* 
     * this is the code that will run whenever an ACTION_CONFIGURATION_CHANGED happens
     * do whatever needs to be done, such as re-reading preferences, 
     * resetting background to user's preferred setting etc.
     */
  }
}

Post a Comment for "Appwidget Keeps Reseting Background To Transparent"