Code example for SharedPreferences

Methods: getStringregisterOnSharedPreferenceChangeListener

0
		NetworkUtils.restoreLoginCookies(mActivity);
	} 
	 
	public void onResume() { 
		setOrientation(); 
		mPrefs.registerOnSharedPreferenceChangeListener(this);
	} 
	 
	public void onPause() { 
		mPrefs.unregisterOnSharedPreferenceChangeListener(this);
	} 
	 
	public void onStop() {} 
	 
	public void onDestroy() {} 
 
	@Override 
	public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
		if(key.equals("orientation")) {
			setOrientation(); 
		} 
	} 
	 
	private void setOrientation() { 
		String orientationStr = mPrefs.getString("orientation", "default");
		int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
		if(orientationStr.equals("portrait")) {
			orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
		} else if(orientationStr.equals("landscape")) {
			orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;