Skip to content Skip to sidebar Skip to footer

Calling Handler.removecallbacks From Ondeleted Method In A Widget Throws A Nullpointerexception

I need to stop the handler when the widget is removed by the user but calling handler.removeCallbacks throws a nullpointerexception from the onDeleted method. I tried other workaro

Solution 1:

The problem is that you can't depend on the same instance of your widget being called by Android each time, and so keeping non-static fields in your widget provider is a problem.

An easy solution would be to use static fields for handler and runnable. It looks like some of the other fields could go away too, for example PieGraph is constructed each time onProgressUpdate is called, so it could be a local. Basically you should avoid all non-static fields in a widget.

Post a Comment for "Calling Handler.removecallbacks From Ondeleted Method In A Widget Throws A Nullpointerexception"