Closed tomwassink closed 3 years ago
This exception is thrown when the Listener is not set or was already unregistered. Maybe your unregister is called twice for some reason? Can you give a little bit more Code?
Thanks for your fast reply!
Variable definition in Service:
private mAppPrefsListener = new OnTrayPreferenceChangeListener() {
@Override
public void onTrayPreferenceChanged(final Collection<TrayItem> items) {
for (TrayItem item : items) {
if (PrefsUtilities.keyIsSpeedSensorGpsUse(item)){
mAlwaysUseGpsSpeedDistance = PrefsUtilities.getSpeedSensorGpsUse(getMultiProcessPreferences());
}
if (item.key().equals(Constants.SCREEN_REFRESH_RATE)){
mScreenRefreshRate = getScreenRefreshRatePreference();
}
}
}
};
RegisterListener in Service onCreate:
getMultiProcessPreferences().registerOnTrayPreferenceChangeListener(mAppPrefsListener);
onDestroy in Service:
@Override
public void onDestroy(){
if (!isDestroyed) {
destroyService();
}
super.onDestroy();
}
In class that extends MultiDexApplication class a onDestroy method which is called when Service (a foreground service) has to stop (i.e. quit app):
public void onDestroy() {
stopService(new Intent(this, JepsterService.class));
isJepsterServiceStarted = false;
}
I just changed to test the code to initialize the mAppPrefsListner via a method which is called in the onCreate method of the Service just before register the listner. Then in the onDestroy part I will set the mAppPrefsListner variable to null after unregister (and as you can see I already check if it is null before..). I will resubmit a beta update to see the results of the launch report.
After changing code as written above I had no issues in the launch report. Published an update today, so let's see if errors will be reported. Keep you posted.
Since update two weeks ago no errors reported. I will close the issue. Thanks for your help.
tray Version 0.12.0
tray is initialized in onStartCommand of a service
Device(s) (issues reported in Play store on Samsung Galaxy S8, A8 and S8+, but in pre launch test on multiple other devices as well )
minSdkVersion 21, compile and targetSDK 29
Stacktrace
For some reason nullpointer exceptions are reported when the code wants to unregister the listener. In the code this is called just before stopping the Service. Code:
...
}
Do you have any explanation or hint why this happens? I can't reproduce it in Android Studio, but i have got multiple reports in the Play Store and also in the automatic pre-launch tests.
Thanks a lot in advance!