Java Code Examples for android.content.SharedPreferences#unregisterOnSharedPreferenceChangeListener()

The following examples show how to use android.content.SharedPreferences#unregisterOnSharedPreferenceChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivitySettings.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);

    unregisterReceiver(interactiveStateReceiver);
    unregisterReceiver(connectivityChangedReceiver);
}
 
Example 2
Source File: ShortcutLauncherFolderActivity.java    From FreezeYou with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    final String uuid = getIntent().getStringExtra("UUID");
    if (uuid != null) {
        final SharedPreferences uuidSp = getSharedPreferences(uuid, MODE_PRIVATE);
        uuidSp.unregisterOnSharedPreferenceChangeListener(this);
    }
    super.onDestroy();
}
 
Example 3
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    /** Cleanup the shared preference listener **/
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 4
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    /** Cleanup the shared preference listener **/
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 5
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    /** Cleanup the shared preference listener **/
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 6
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    /** Cleanup the shared preference listener **/
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 7
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    /** Cleanup the shared preference listener **/
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 8
Source File: MainActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    /** Cleanup the shared preference listener **/
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 9
Source File: GameActivity.java    From privacy-friendly-dame with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();

    mHandler.removeCallbacksAndMessages(null);
    game = null;

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPreferences.unregisterOnSharedPreferenceChangeListener(preferencesChangeListener);
}
 
Example 10
Source File: SecurePreferences.java    From secure-storage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Unregisters SecureStorageChangeListener from SecureStorage
 *
 * @param context  Context is used internally
 * @param listener Provided listener with given behaviour from the developer that will be unregistered
 */
public static void unregisterOnSharedPreferenceChangeListener(@NonNull Context context,
                                                              @NonNull SharedPreferences.OnSharedPreferenceChangeListener listener) {
    Context applicationContext = context.getApplicationContext();
    SharedPreferences preferences = applicationContext
            .getSharedPreferences(KEY_SHARED_PREFERENCES_NAME, MODE_PRIVATE);
    preferences.unregisterOnSharedPreferenceChangeListener(listener);
}
 
Example 11
Source File: SettingsManager.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Close a SharedPreferences file by custom scope.
 * The file isn't explicitly closed (the SharedPreferences API makes
 * this unnecessary), so the real work is to unregister any known
 * SharedPreferenceListeners from this SharedPreferences instance.
 * <p>
 * It's important to do this as camera and modules change, because
 * we don't want old SharedPreferences listeners executing on
 * cameras/modules they are not compatible with.
 */
protected void closePreferences(SharedPreferences preferences)
{
    synchronized (mLock)
    {
        for (OnSharedPreferenceChangeListener listener : mSharedPreferenceListeners)
        {
            preferences.unregisterOnSharedPreferenceChangeListener(listener);
        }
    }
}
 
Example 12
Source File: MainActivity.java    From azure-notificationhubs-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDestroy() {
    if (onSharedPreferenceChangeListener != null) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        sharedPreferences.unregisterOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
        onSharedPreferenceChangeListener = null;
    }
    super.onDestroy();
}
 
Example 13
Source File: ActivitySettings.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
private void xmlImport(InputStream in) throws IOException, SAXException, ParserConfigurationException {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
    prefs.edit().putBoolean("enabled", false).apply();
    ServiceSinkhole.stop("import", this, false);

    XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
    XmlImportHandler handler = new XmlImportHandler(this);
    reader.setContentHandler(handler);
    reader.parse(new InputSource(in));

    xmlImport(handler.application, prefs);
    xmlImport(handler.wifi, getSharedPreferences("wifi", Context.MODE_PRIVATE));
    xmlImport(handler.mobile, getSharedPreferences("other", Context.MODE_PRIVATE));
    xmlImport(handler.screen_wifi, getSharedPreferences("screen_wifi", Context.MODE_PRIVATE));
    xmlImport(handler.screen_other, getSharedPreferences("screen_other", Context.MODE_PRIVATE));
    xmlImport(handler.roaming, getSharedPreferences("roaming", Context.MODE_PRIVATE));
    xmlImport(handler.lockdown, getSharedPreferences("lockdown", Context.MODE_PRIVATE));
    xmlImport(handler.apply, getSharedPreferences("apply", Context.MODE_PRIVATE));
    xmlImport(handler.notify, getSharedPreferences("notify", Context.MODE_PRIVATE));
    xmlImport(handler.blocklist, getSharedPreferences(PREF_BLOCKLIST, Context.MODE_PRIVATE));

    // Reload blocklist
    AppBlocklistController.getInstance(this).loadSettings(this);

    // Upgrade imported settings
    ReceiverAutostart.upgrade(true, this);

    DatabaseHelper.clearCache();

    // Refresh UI
    prefs.edit().putBoolean("imported", true).apply();
    prefs.registerOnSharedPreferenceChangeListener(this);
}
 
Example 14
Source File: FragmentSettings.java    From fingen with Apache License 2.0 4 votes vote down vote up
@Override
public void onDestroyView() {
    super.onDestroyView();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    prefs.unregisterOnSharedPreferenceChangeListener(listener);
}
 
Example 15
Source File: ServiceTileSynchronize.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
public void onStopListening() {
    Log.i("Stop tile synchronize");
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 16
Source File: FragmentPro.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onPause() {
    super.onPause();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    prefs.unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 17
Source File: ServiceSynchronize.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onDestroy() {
        EntityLog.log(this, "Service destroy");

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        prefs.unregisterOnSharedPreferenceChangeListener(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            unregisterReceiver(idleModeChangedReceiver);

        unregisterReceiver(connectionChangedReceiver);

        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        cm.unregisterNetworkCallback(networkCallback);

        liveAccountNetworkState.postDestroy();

        try {
            stopForeground(true);
        } catch (Throwable ex) {
            Log.e(ex);
/*
            OnePlus A6013 - Android 9

            java.lang.RuntimeException: Unable to stop service eu.faircode.email.ServiceSynchronize@3995fc9: java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
                    at android.app.ActivityThread.handleStopService(ActivityThread.java:3908)
                    at android.app.ActivityThread.access$1900(ActivityThread.java:209)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1826)
                    at android.os.Handler.dispatchMessage(Handler.java:106)
                    at android.os.Looper.loop(Looper.java:193)
                    at android.app.ActivityThread.main(ActivityThread.java:6954)
                    at java.lang.reflect.Method.invoke(Method.java:-2)
                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
            Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
                    at android.os.Parcel.createException(Parcel.java:1956)
                    at android.os.Parcel.readException(Parcel.java:1918)
                    at android.os.Parcel.readException(Parcel.java:1868)
                    at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:5111)
                    at android.app.Service.stopForeground(Service.java:724)
                    at android.app.Service.stopForeground(Service.java:710)
*/
        }

        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(Helper.NOTIFICATION_SYNCHRONIZE);

        super.onDestroy();
    }
 
Example 18
Source File: ReadingActivity.java    From IslamicLibraryAndroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceListener);
}
 
Example 19
Source File: ServiceTileMain.java    From tracker-control-android with GNU General Public License v3.0 4 votes vote down vote up
public void onStopListening() {
    Log.i(TAG, "Stop listening");
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.unregisterOnSharedPreferenceChangeListener(this);
}
 
Example 20
Source File: SharedPreferencesPropertyBackend.java    From memetastic with GNU General Public License v3.0 4 votes vote down vote up
public void unregisterPreferenceChangedListener(final SharedPreferences pref, SharedPreferences.OnSharedPreferenceChangeListener value) {
    pref.unregisterOnSharedPreferenceChangeListener(value);
}