Destroy an instance
-
Hey,
Below is my code to start/stop Flic feature on my application.
How do I remove flic buttons from Flic manager?Here is my code:
findPreference(INTEGRATE_FLIC).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue.toString().equals("true")) { PreferenceManager.getDefaultSharedPreferences(getContext()).edit() .putBoolean(INTEGRATE_FLIC, false).apply(); FlicManager.setAppCredentials(FLIC_APP_ID, FLIC_APP_SECRET, FLIC_APP_NAME); if (!isAppInstalled(getContext(), FLIC_PACKAGE_NAME)) { flicNotInstalled(); } else { FlicManager.getInstance(getContext(), new FlicManagerInitializedCallback() { @Override public void onInitialized(FlicManager manager) { manager.initiateGrabButton(getActivity()); } }); } } else { //TODO: Invalidate button here! //FlicManager.destroyInstance(); PreferenceManager.getDefaultSharedPreferences(getContext()).edit() .putBoolean(INTEGRATE_FLIC, false).apply(); } return true; } });
If I use FlicManager.destroyInstance(),
I'am getting the following exception:--------- beginning of crash 2019-08-20 16:14:10.718 3751-3751/com.sensennetworks.senanpr E/AndroidRuntime: FATAL EXCEPTION: main Process: com.sensennetworks.senanpr, PID: 3751 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.Context.unbindService(android.content.ServiceConnection)' on a null object reference at io.flic.lib.FlicManager.destroyInstanceInternal(FlicManager.java:402) at io.flic.lib.FlicManager.destroyInstance(FlicManager.java:388) at com.sensennetworks.senanpr.ui.AdvanceSettingsActivity$OtherFiltersPreferenceFragment$2.onPreferenceChange(AdvanceSettingsActivity.java:1103) at android.preference.Preference.callChangeListener(Preference.java:1080) at android.preference.TwoStatePreference.onClick(TwoStatePreference.java:65) at android.preference.Preference.performClick(Preference.java:1135) at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:249) at android.widget.AdapterView.performItemClick(AdapterView.java:318) at android.widget.AbsListView.performItemClick(AbsListView.java:1192) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3184) at android.widget.AbsListView$3.run(AbsListView.java:4166) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6806) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873) 2019-08-20 16:14:10.728 3751-3751/com.sensennetworks.senanpr E/MQSEventManagerDelegate: failed to get MQSService.
How do I workaround this?