Context getSharedPreferences - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:getBroadcast, getSharedPreferences, getSystemService
     */ 
    public void onRegistered(Context context, String registrationId) throws IOException {
        // registrationId will also be saved 
    } 
 
    /** 
     * Called when the device has been unregistered. 
     */ 
    public void onUnregistered(Context context) {
    } 
 
     
    @Override 
    public final void onHandleIntent(Intent intent) {
        try { 
            Context context = getApplicationContext();
            if (intent.getAction().equals(REGISTRATION_CALLBACK_INTENT)) {
                handleRegistration(context, intent);
            } else if (intent.getAction().equals(C2DM_INTENT)) {
                onMessage(context, intent);

8
CodeRank
This code example shows how to use the following methods:getApplicationContext, getResources, getSharedPreferences
 
    private LocalBluetoothPreferences() { 
    } 
 
    private static SharedPreferences getSharedPreferences(Context context) {
        return context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    } 
 
    static long getDiscoverableEndTimestamp(Context context) {
        return getSharedPreferences(context).getLong(
                KEY_DISCOVERABLE_END_TIMESTAMP, 0);
    } 
 
    static boolean shouldShowDialogInForeground(Context context,
            String deviceAddress) {
        LocalBluetoothManager manager = LocalBluetoothManager.getInstance(context);
        if (manager == null) {
            return false; 
        } 
 

8
CodeRank
This code example shows how to use the following methods:getBroadcast, getSharedPreferences, getSystemService
    scheduleAlarms(listener, ctxt, true);
  } 
 
  public static void scheduleAlarms(AlarmListener listener,
                                    Context ctxt, boolean force) {
    SharedPreferences prefs=ctxt.getSharedPreferences(NAME, 0);
    long lastAlarm=prefs.getLong(LAST_ALARM, 0);
 
    if (lastAlarm == 0
        || force
        || (System.currentTimeMillis() > lastAlarm && System.currentTimeMillis()
            - lastAlarm > listener.getMaxAge())) {
      AlarmManager mgr=
          (AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
      Intent i=new Intent(ctxt, AlarmReceiver.class);
      PendingIntent pi=PendingIntent.getBroadcast(ctxt, 0, i, 0);
 
      listener.scheduleAlarms(mgr, pi, ctxt);
    } 
  } 

8
CodeRank
This code example shows how to use the following methods:getApplicationContext, getSharedPreferences
        this.cacheKey = Utility.isNullOrEmpty(cacheKey) ? DEFAULT_CACHE_KEY : cacheKey;
 
        // If the application context is available, use that. However, if it isn't 
        // available (possibly because of a context that was created manually), use 
        // the passed in context directly. 
        Context applicationContext = context.getApplicationContext();
        context = applicationContext != null ? applicationContext : context;
 
        this.cache = context.getSharedPreferences(
                this.cacheKey,
                Context.MODE_PRIVATE);
    } 
 
    /** 
     * Returns a Bundle that contains the information stored in this cache 
     * 
     * @return A Bundle with the information contained in this cache 
     */ 
    public Bundle load() {
        Bundle settings = new Bundle();
7
CodeRank
This code example shows how to use the following methods:bindService, getContentResolver, getPackageManager, getSharedPreferences
 
	private final SharedPreferences mPreferences; //Preferences to store the OpenUDID
	private final Random mRandom;
	 
	private OpenUDID_manager(Context context) {
		mPreferences =  context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
		mContext = context;
		mRandom = new Random();
		mReceivedOpenUDIDs = new HashMap<String, Integer>();
	} 
	 
	@Override 
  	public void onServiceConnected(ComponentName className, IBinder service) {
		//Get the OpenUDID from the remote service 
		try { 
			//Send a random number to the service 
			android.os.Parcel data = android.os.Parcel.obtain(); 
			data.writeInt(mRandom.nextInt());
			android.os.Parcel reply = android.os.Parcel.obtain(); 
			service.transact(1, android.os.Parcel.obtain(), reply, 0);

7
CodeRank
This code example shows how to use the following methods:getSharedPreferences
     * If result is empty, the registration has failed. 
     * 
     * @return registration id, or empty string if the registration is not complete. 
     */ 
    public static String getRegistrationId(Context context) {
        final SharedPreferences prefs = context.getSharedPreferences(
                PREFERENCE,
                Context.MODE_PRIVATE);
        String registrationId = prefs.getString("dm_registration", "");
        return registrationId;
    } 
 
    public static long getLastRegistrationChange(Context context) {
        final SharedPreferences prefs = context.getSharedPreferences(
                PREFERENCE,
                Context.MODE_PRIVATE);
        return prefs.getLong(LAST_REGISTRATION_CHANGE, 0);
    } 
     
    static long getBackoff(Context context) {
7
CodeRank
This code example shows how to use the following methods:getSharedPreferences
                    mode);
        } else if (context instanceof Application) {
            prefs = ((Application) context).superGetSharedPreferences(name,
                    mode);
        } else { 
            prefs = context.getSharedPreferences(name, mode);
        } 
    } 
 
    @Override 
    public boolean contains(String key) {
        return prefs.contains(key);
    } 
 
    @Override 
    public Editor edit() { 
        return new EditorImpl(prefs.edit());
    } 
 
    @Override 
7
CodeRank
This code example shows how to use the following methods:getApplicationContext, getSharedPreferences
        this.cacheKey = Utility.isNullOrEmpty(cacheKey) ? DEFAULT_CACHE_KEY : cacheKey;
 
        // If the application context is available, use that. However, if it isn't 
        // available (possibly because of a context that was created manually), use 
        // the passed in context directly. 
        Context applicationContext = context.getApplicationContext();
        context = applicationContext != null ? applicationContext : context;
 
        this.cache = context.getSharedPreferences(
                this.cacheKey,
                Context.MODE_PRIVATE);
    } 
 
    /** 
     * Returns a Bundle that contains the information stored in this cache 
     * 
     * @return A Bundle with the information contained in this cache 
     */ 
    public Bundle load() {
        Bundle settings = new Bundle();
7
CodeRank
This code example shows how to use the following methods:getSharedPreferences, startActivity, makeText
		} else if (intent.getStringExtra("unregistered") != null) {
			Log.d("c2dm", "unregistered");
 
		} else if (registration != null) {
 
			Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
			editor.putString(REGISTRATION_KEY, registration);
			System.out.println(registration);
			editor.commit();
 
			Intent accountIntent = new Intent(context,AccountList.class);
			accountIntent.putExtra("regKey",registration) ;
			accountIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
			context.startActivity(accountIntent);
		} 
		Toast.makeText(context, registration, Toast.LENGTH_LONG);
	} 
 
	private void handleMessage(Context context, Intent intent)
	{ 
		Log.v(TAG,"handleMessage");
6
CodeRank
This code example shows how to use the following methods:getSharedPreferences

Related Context getSharedPreferences Questions & Answers:

Other Context getSharedPreferences Examples

109:	
110:			// Shared Preferences
111:			mSharedPreferences = getApplicationContext().getSharedPreferences(
112:					"MyPref", 0);
113:

Read More

35:		public SessionManager(Context context){
36:			this._context = context;
37:			pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
38:			editor = pref.edit();
39:		}

Read More

35:		public SessionManager(Context context){
36:			this._context = context;
37:			pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
38:			editor = pref.edit();
39:		}

Read More

6:	        // Deletes previously stored password policy.
7:	        super.onDisabled(context, intent);
8:	        SharedPreferences prefs = context.getSharedPreferences(APP_PREF, Activity.MODE_PRIVATE);
9:	        prefs.edit().clear().commit();
10:	    }

Read More

getSharedPreferences Method Overview
Retrieve and hold the contents of the preferences file 'name', returning a SharedPreferences through which you can retrieve and modify its values.
See Code Examples for other Android Context Methods: