Never use member variables in an AppWidgetProvider.
A AppWidgetProvider
object has a short lifecycle. It is instantiated by Android for a function call when needed and destroyed afterwards. That's the reason the temp
variable remains empty. The LocationListener
sets temp
in one instance of AppWidgetProvider
and Android calls onUpdate()
via a new instance .
In order to keep your widget's data (the location) persistent, use one of the data storage options of Android: Android Data Storage
One a side note: there are some examples on stackoverflow of a location widget.