SharedPreferences registerOnSharedPreferenceChangeListener - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SharedPreferences registerOnSharedPreferenceChangeListener method.

This code example shows how to use the following methods:registerOnSharedPreferenceChangeListener
		editor.commit();
	} 
 
	public void registerOnSharedPreferenceChangeListener( 
			SharedPreferences.OnSharedPreferenceChangeListener listener) {
		m_prefs.registerOnSharedPreferenceChangeListener(listener);
	} 
 
	public void unregisterOnSharedPreferenceChangeListener( 
			SharedPreferences.OnSharedPreferenceChangeListener listener) {
		m_prefs.unregisterOnSharedPreferenceChangeListener(listener);
	} 
 
	public void dump() { 
		Map<String, ?> keys = m_prefs.getAll();
 
		for (Map.Entry<String, ?> entry : keys.entrySet()) {
			Log.d("map values", entry.getKey() + ": "
					+ entry.getValue().toString());
		} 
6
CodeRank
This code example shows how to use the following methods:getInt, registerOnSharedPreferenceChangeListener
 
    btn=new Button(this);
    setContentView(btn);
    prefs=PreferenceManager.getDefaultSharedPreferences(this);
 
    prefs.registerOnSharedPreferenceChangeListener(this);
    btn.setText(String.valueOf(prefs.getInt(KEY, 0)));
    btn.setOnClickListener(this);
  } 
 
  @Override 
  public void onSharedPreferenceChanged(SharedPreferences prefs,
                                        String key) {
    btn.setText(String.valueOf(prefs.getInt(KEY, 0)));
  } 
 
  @Override 
  public void onClick(View v) {
    prefs.edit().putInt(KEY, prefs.getInt("test", 0) + 1).apply();
  } 
7
CodeRank
This code example shows how to use the following methods:getString, registerOnSharedPreferenceChangeListener
 
    @Override 
    public void onCreate() { 
	super.onCreate(); 
	mSettings = PreferenceManager.getDefaultSharedPreferences(this);
	String login = mSettings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "");
	String password = mSettings.getString(BeemApplication.ACCOUNT_PASSWORD_KEY, "");
	mIsAccountConfigured = !("".equals(login) || "".equals(password));
	mSettings.registerOnSharedPreferenceChangeListener(mPreferenceListener);
	 
    } 
 
    @Override 
    public void onTerminate() { 
	super.onTerminate(); 
	mSettings.unregisterOnSharedPreferenceChangeListener(mPreferenceListener);
    } 
 
    /** 
     * Tell if Beem is connected to a XMPP server. 
6
CodeRank
This code example shows how to use the following methods:registerOnSharedPreferenceChangeListener
	@Override 
	public void onCreate() { 
		super.onCreate(); 
		this.appSettings = PreferenceManager
				.getDefaultSharedPreferences(getApplicationContext());
		this.appSettings.registerOnSharedPreferenceChangeListener(this);
		this.appInst = (MobileOrgApplication) this.getApplication();
		this.alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
	} 
 
	@Override 
	public void onDestroy() { 
		unsetAlarm(); 
		this.appSettings.unregisterOnSharedPreferenceChangeListener(this);
		super.onDestroy(); 
	} 
	 
	public static void stopAlarm(Context context) {
		Intent intent = new Intent(context, SyncService.class);
		intent.putExtra(ACTION, SyncService.STOP_ALARM);
6
CodeRank
This code example shows how to use the following methods:getInt, registerOnSharedPreferenceChangeListener
 
    btn=new Button(this);
    setContentView(btn);
    prefs=PreferenceManager.getDefaultSharedPreferences(this);
 
    prefs.registerOnSharedPreferenceChangeListener(this);
    btn.setText(String.valueOf(prefs.getInt(KEY, 0)));
    btn.setOnClickListener(this);
  } 
 
  @Override 
  public void onSharedPreferenceChanged(SharedPreferences prefs,
                                        String key) {
    btn.setText(String.valueOf(prefs.getInt(KEY, 0)));
  } 
 
  @Override 
  public void onClick(View v) {
    prefs.edit().putInt(KEY, prefs.getInt("test", 0) + 1).apply();
  } 
7
CodeRank
This code example shows how to use the following methods:registerOnSharedPreferenceChangeListener
  @Override 
  public void onCreate() { 
    super.onCreate(); 
 
    prefs=PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(this);
  } 
 
  @TargetApi(11) 
  @Override 
  public void onSharedPreferenceChanged(SharedPreferences prefs,
                                        String key) {
    Intent i=new Intent(ACTION_SYNC_PREF);
    Object value=prefs.getAll().get(key);
 
    i.putExtra(EXTRA_SENDER, getPackageName());
    i.putExtra(EXTRA_KEY, key);
 
    if (value instanceof Boolean) {
      i.putExtra(EXTRA_VALUE, (Boolean)value);
6
CodeRank
This code example shows how to use the following methods:getBoolean, registerOnSharedPreferenceChangeListener
        mPrefs.unregisterOnSharedPreferenceChangeListener(this);
        mSwitch.setOnCheckedChangeListener(null);
    } 
 
    public void resume() { 
        mPrefs.registerOnSharedPreferenceChangeListener(this);
        setSwitchChecked(mPrefs.getBoolean(mKey, mDefValue));
        mSwitch.setOnCheckedChangeListener(this);
    } 
 
    @Override 
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (key.equals(mKey)) {
            setSwitchChecked(sharedPreferences.getBoolean(mKey, mDefValue));
        } 
    } 
 
    private void setSwitchChecked(boolean checked) {
        if (checked != mSwitch.isChecked()) {
            mStateMachineEvent = true;
7
CodeRank
This code example shows how to use the following methods:edit, getString, registerOnSharedPreferenceChangeListener
    public void onCreate() { 
        // TODO Auto-generated method stub 
        super.onCreate(); 
 
        prefs = PreferenceManager.getDefaultSharedPreferences(this);
        prefs.registerOnSharedPreferenceChangeListener(this);
         
        //prefs.edit().remove("device_id").commit(); 
         
        String device_id = prefs.getString("device_id", null);
         
        FusionInventory.log(this, device_id, Log.VERBOSE);
         
              
        if(device_id == null) {
            
           TelephonyManager mTM= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
           prefs.edit()
                .putString("device_id", String.format("%s-%s",mTM.getDeviceId(),DateFormat.format("yyyy-MM-dd-kk-mm-ss", System.currentTimeMillis())))
                .commit();

6
CodeRank
This code example shows how to use the following methods:getString, registerOnSharedPreferenceChangeListener
    @Override 
    protected void onResume() { 
        super.onResume(); 
        SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
        setSummaries(sharedPreferences, TX_FEE_PREF);
        sharedPreferences.registerOnSharedPreferenceChangeListener(this);
    } 
 
    @Override 
    protected void onPause() { 
        super.onPause(); 
        getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
    } 
 
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (TX_FEE_PREF.equals(key)) {
            double txFee = Double.NaN;
            String txFeeString = sharedPreferences.getString(TX_FEE_PREF, "0.005");
            try { 
                txFee = Double.parseDouble(txFeeString);

6
CodeRank
This code example shows how to use the following methods:getString, registerOnSharedPreferenceChangeListener
        return sharedPrefs;
    } 
 
    protected void setSharedPrefs(SharedPreferences sharedPrefs) {
        this.sharedPrefs = sharedPrefs;
        sharedPrefs.registerOnSharedPreferenceChangeListener(this);
        initFromPrefs(sharedPrefs);
    } 
 
    @Override 
    public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
        if (PREF_SERVER_LOGIN.equals(key) || PREF_SERVER_PASSWORD.equals(key)
                || PREF_SERVER_URL.equals(key)) {
            initFromPrefs(prefs);
            androidContext.sendBroadcast(new Intent(
                    NuxeoBroadcastMessages.NUXEO_SETTINGS_CHANGED)); 
        } 
    } 
 
    protected void initFromPrefs(SharedPreferences prefs) {

7
CodeRank

Related SharedPreferences registerOnSharedPreferenceChangeListener Questions & Answers:

registerOnSharedPreferenceChangeListener Method Overview
Registers a callback to be invoked when a change happens to a preference.
See Code Examples for other Android SharedPreferences Methods: