In short ... I have a widget, you can see the important part below
public class ExampleWidget extends AppWidgetProvider {
private PhoneStateListener listener;
private TelephonyManager telephonyManager;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
listener = new PhoneStateListener() {
@Override
public void onDataConnectionStateChanged(int state) {
}
};
telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(listener,
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}
@Override
public void onDisabled(Context context) {
telephonyManager.listen(listener, PhoneStateListener.LISTEN_NONE);
super.onDisabled(context);
}
}
and I get a nullpointer exception telephonyManager.listen(listener, PhoneStateListener.LISTEN_NONE);when I remove the widget from the main screen.
What am I missing?
user874649
source
share