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 user changes the background preference the setting is saved and the background is updated using below code:
public static Bitmap setBackground (int bgcolor)
{
{
Bitmap.Config config=Bitmap.Config.ARGB_8888;
Bitmap bitmap=Bitmap.createBitmap(2, 2, config);
Canvas canvas=new Canvas(bitmap);
canvas.drawColor(bgcolor);
return bitmap;
}
}
/* set background */
if (ExampleWidgetProvider.background==1)
views.setImageViewBitmap(R.id.bgcolor, setBackground(Color.parseColor("#aaaaaaaa")));
else
views.setImageViewBitmap(R.id.bgcolor, setBackground(Color.parseColor("#00000000")));
One user reports that the background is changed back to transparent when he has set it to be semi-transparent. This may happen seemingly random within a few minutes an hour or half a day.
I realised this is a problem with the background and not some kind of preference resetting because I sent the user a version of the appwidget that will always change the background to semi-transparent, i.e. using:
/* set background */
if (ExampleWidgetProvider.background==1)
views.setImageViewBitmap(R.id.bgcolor, setBackground(Color.parseColor("#aaaaaaaa")));
else
views.setImageViewBitmap(R.id.bgcolor, setBackground(Color.parseColor("#aaaaaaaa")));
But interestingly that didn't fix it. Since the default in the xml is set to transparent I am suspecting the app somehow is either restarted or redrawn and the default layout is being used.
How can I detect and/or work around this?
Update: User (as expected) confirmed fix which permanently changes background colour in xml to semi transparent is working. Which means the system is resetting the background for some unknown reason.
The user uses an LG PG 970 V. 2.2.2 and for what it's worth he is using "Juice Defender Ultimate" and has it configured to not connect to the internet during the night. My appwidget does connect to the internet at regular intervals.