Hello
I've created a simple home screen widget for the Android 2.2. It comprises of a button and a background image only. What im trying to do is that when user clicks on the button, i show a Toast msg with a number. This number is to be increased every time button is clicked, starting from zero.
So ive declared my variable as follows:
public class MainWidget extends AppWidgetProvider {
private static int myNum = 0;
...
And in the onReceive event I do this (after checking the button was clicked):
myNum += 1;
Toast.makeText(context, "myNum:" + myNum, Toast.LENGTH_LONG).show();
This works fine. Whenever user clicks the button the number is increased by 1 and displayed on screen. I want this number to be instance-specific. If i remove the widget from the home screen and add it back again, the numbering continues from the point where it was last time. For example if number is currently 4. I remove the widget and add back and click button, it will display 5. I want it to restart
from 1.
I've tried various declarations:
private int myNum = 0;
int myNum = 0;
static int myNum = 0;
But nothing work. If I remove the "static" keyword then the number doesn't increase at all. Every time the button is clicked, it keeps displaying 1. I want the number to be instance-specific i.e. to be restarted from 1 whenever the widget is removed and added back. Also if the user places more than one widgets on his home screen then both the widgets' numbering should be independent from each other. How do I achieve this? Seems like a simple task but totally confused how to declare my integer. Please anyone help.
Here is the complete code:
click here to view[
^]
-Faraz Azhar
@Nagy: No thats not the issue. I've put Toasts msgs on every event.. OnDeleted, OnDisabled, etc. So I know all these events are firing properly.
Have a look at this link below. Another person is also having the exact same problem. Maybe you can understand better in his wording:
Gmail Text Cloud Widget[
^]