Hi all,
I'd like to rewrite part of an app as a widget, but I'm not sure about the persistence of a few values so I ask it here.
Originally my app was made up of two services implementing static broadcast receivers and two activities, one for toggling on/off the special actions in the services and the other for config purposes.
Now, drawing the widget, I placed on it two buttons, one for the old on/off action and the other to start the config activity. So far so good.
My doubt concerns the correct placement of those global vars needed for the services proper functioning.
Should I place them in the widget-service globals?
If so, does the widget life cycle assures those vars are always available with their current values to an eventually starting service requesting them? Or are there times when the OS could kill the widget (to recreate it later) and an OS started service could risk not to find the needed var?
If you confirm that a var placed inside the widget-service is somewhat "permanent" I would code my stuff this way:
1. all relevant vars in widget_service globals
2. on widget_service create do all the initialize needed (file, list..)
3. on widget_service start do read vars current values from file
Now, using the buttons on the widget I can modify vars' values and save them to file.
If one of the broadcast receiver starts, it reads current values from the widget_vars globals and all works as expected.
Last point. If the above scheme works, what happens if I remove the widget from its home screen?
I mean, what happens if the OS sends the broadcast set in the manifest? There's no widget running to offer the called service the vars it needs..so what?
Sorry if all the above is worded in a so confused way, but I find it difficult to explain this stuff even to myself :-(
Umberto