Android widget textview not updating

The problem was that the widget would randomly become unresponsive.

After large doses of caffeine and Stack Overflow, I finally figured out what was wrong.

I will demonstrate the problem and its solution in this post. The top Text View is the user configurable part of the widget, in this case the user name.

You can download the code for the sample widget here and try it yourself using Android Studio with the Android SDK, or just follow along with the code snippets given below. The button is used to change the user name in the top Text View.

It also says in the documents that the on Update method of the widget is not called by the configuration activity when it is launched and that it is important to manually trigger a widget update when you close your configuration activity. Using Log statements to document the widget lifecycle, on Update called when the configuration activity is launched.

Also, up until Android API level 18 (it is fixed in level 19), the widget is not deleted when you back out of the configuration activity, thus leaving you with an invisible widget that is taking up resources — what I call a zombie widget.

As you can see from the code, it simplifies the app by ensuring no parts of the app are tightly coupled to the other, this is important for creating simplistic and extensible code.

Developing an Android home screen app widget is not for the faint of heart.

Following instructions online I had trouble creating a widget that had a configuration button on it and used an Alarm Manager to update the widget in real time.

The bottom Text View shows the current date and time and is updated every second.

Android widgets in their standard form can only be updated at a minimum of every 30 minutes, so our example widget gets around this by using an Alarm Manager that triggers every second.

Filled text fields have a solid background color and draw more attention, especially in layouts where the field is surrounded by other elements.

To use a filled text field, apply the following style to your provides two height variations for filled and outline text fields, standard and dense. In order to reduce the height of a text box, you can use a dense style, which will reduce the vertical padding within the text box.

Leave a Reply