fixed FC when changing language, order of Create/Destroy calls is not
guaranteed
This commit is contained in:
parent
1572cc7160
commit
3defd7cb04
1 changed files with 11 additions and 1 deletions
|
@ -25,6 +25,7 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private BroadcastReceiver broadcastReceiver;
|
private BroadcastReceiver broadcastReceiver;
|
||||||
private CheckBoxPreference routeServiceEnabled;
|
private CheckBoxPreference routeServiceEnabled;
|
||||||
|
private SettingsActivity activity;
|
||||||
|
|
||||||
public OsmandBackgroundServicePlugin(OsmandApplication app) {
|
public OsmandBackgroundServicePlugin(OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
@ -54,8 +55,13 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void settingsActivityDestroy(final SettingsActivity activity){
|
public void settingsActivityDestroy(final SettingsActivity activity){
|
||||||
if(broadcastReceiver != null) {
|
unregisterReceiver(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unregisterReceiver(final SettingsActivity activity) {
|
||||||
|
if (activity != null && this.activity == activity && broadcastReceiver != null) {
|
||||||
activity.unregisterReceiver(broadcastReceiver);
|
activity.unregisterReceiver(broadcastReceiver);
|
||||||
|
broadcastReceiver = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +80,11 @@ public class OsmandBackgroundServicePlugin extends OsmandPlugin {
|
||||||
grp.setSummary(R.string.osmand_service_descr);
|
grp.setSummary(R.string.osmand_service_descr);
|
||||||
((PreferenceCategory) screen.findPreference("global_settings")).addPreference(grp);
|
((PreferenceCategory) screen.findPreference("global_settings")).addPreference(grp);
|
||||||
|
|
||||||
|
//unregister old service. Note, the order of calls of Create/Destroy is not guaranteed!!
|
||||||
|
unregisterReceiver(this.activity);
|
||||||
|
|
||||||
routeServiceEnabled = new CheckBoxPreference(activity);
|
routeServiceEnabled = new CheckBoxPreference(activity);
|
||||||
|
this.activity = activity;
|
||||||
broadcastReceiver = new BroadcastReceiver(){
|
broadcastReceiver = new BroadcastReceiver(){
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|
Loading…
Reference in a new issue