views:

644

answers:

2

I have a widget that changes some system settings, but it will not take right away. It seems like I need to refresh the system settings for it to take. How do you change some system settings from a widget that take instantly?

when my widget is pressed it goes to an activity with a blank background to change the system settings. one of the settings that are changed is the display brightness. this is the code i use to change the display brightness. once i change the settings i call the finish function to exit the activity so i am not stuck there after the settings are changed. One thing i did notice is that if i didnt exit the activity the settings did change, but i was stuck in the activity. its when i added the class.this.finish(); to exit the activity that the settings don't change.

android.provider.Settings.System.putInt(getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS, brightness); // 0-255 
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness / 255.0f;
getWindow().setAttributes(lp);
A: 

The real way to adjust the brightness for the system is not visible in the SDK. The code you have is as good as it gets -- the setting will take effect on next reboot, the screenBrightness setting will affect the current activity.

CommonsWare
yea, i found that that screenbrightness will change the setting for the current activity, but when i exit out the activity the system setting for the brightness will then work. but the issue is when i do this for a widget, it doesn't take when i use the finish(); command right after i change the settings.
John
Screen brightness changes just may not work well from an app widget.
CommonsWare
k, thanks for trying to help
John
A: 

found the answer, I was exiting the activity to quickly. for some reason i need to delay my exit for a few hundred milliseconds so the changes take place.

John