SharedPreferences getLong - 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 getLong method.

This code example shows how to use the following methods:getLong, getString
	} 
	 
	public void load(Context context) {
		if(!loaded) {
			SharedPreferences prefs = context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
			c2DMRegistrationId = prefs.getString("c2DMRegistrationId", null);
			registeredUserId = prefs.getLong("registeredUserId", -1L);
			pendingC2DMRequestTime = prefs.getLong("pendingC2DMRequestTime", 0);
			pendingSocializeRequestTime = prefs.getLong("pendingSocializeRequestTime", 0);
			lastC2DMRegistrationTime = prefs.getLong("lastC2DMRegistrationTime", 0);
			lastSocializeRegistrationTime = prefs.getLong("lastSocializeRegistrationTime", 0);
			 
			if(logger != null && logger.isDebugEnabled()) {
				logger.debug("Loaded notification state with registration id [" +
						c2DMRegistrationId +
						"], user id [" + 
						registeredUserId +
						"]"); 
			}		 
		} 
8
CodeRank
This code example shows how to use the following methods:getLong
		return sharedPrefs.getInt(key, defValue);
	} 
 
	@Override 
	public long getLong (String key, long defValue) {
		return sharedPrefs.getLong(key, defValue);
	} 
 
	@Override 
	public float getFloat (String key, float defValue) {
		return sharedPrefs.getFloat(key, defValue);
	} 
 
	@Override 
	public String getString (String key, String defValue) {
		return sharedPrefs.getString(key, defValue);
	} 
 
	@Override 
	public Map<String, ?> get () {
7
CodeRank
This code example shows how to use the following methods:getBoolean, getLong
		} 
		// If a lock pattern is set we need to check the time for when the last 
		// activity was open. If it's been more than two seconds the user 
		// will have to enter the lock pattern to continue. 
		long currentTime = SystemClock.elapsedRealtime();
		long lockedAt = mPrefs.getLong("locked_at", currentTime-10000);
		long timedif = Math.abs(currentTime - lockedAt);
		if (timedif > 2000) {
		    launchPatternLock(); 
		} 
        else { 
            mHasLoaded = true;          
        } 
	} 
 
	private void launchPatternLock() { 
        Intent intent = new Intent(this, ConfirmLockPattern.class);
        intent.putExtra(ConfirmLockPattern.DISABLE_BACK_KEY, true);
        intent.putExtra(ConfirmLockPattern.HEADER_TEXT, getText(R.string.patternlock_header));
        startActivityForResult(intent, PATTERNLOCK_UNLOCK);         

7
CodeRank
This code example shows how to use the following methods:edit, getBoolean, getInt, getLong
     * @return the wall clock time ({@link System#currentTimeMillis()}) when the 
     * next operation should be attempted -- immediately, if the return value is 
     * before the current time. 
     */ 
    public long getNextTimeMillis(Options options) {
        boolean enabledState = mStorage.getBoolean(PREFIX + "enabledState", true);
        if (!enabledState) return Long.MAX_VALUE;
 
        boolean permanentError = mStorage.getBoolean(PREFIX + "permanentError", false);
        if (permanentError) return Long.MAX_VALUE;
 
        // We do quite a bit of limiting to prevent a clock rollback from totally 
        // hosing the scheduler.  Times which are supposed to be in the past are 
        // clipped to the current time so we don't languish forever. 
 
        int errorCount = mStorage.getInt(PREFIX + "errorCount", 0);
        long now = currentTimeMillis();
        long lastSuccessTimeMillis = getTimeBefore(PREFIX + "lastSuccessTimeMillis", now);
        long lastErrorTimeMillis = getTimeBefore(PREFIX + "lastErrorTimeMillis", now);
        long triggerTimeMillis = mStorage.getLong(PREFIX + "triggerTimeMillis", Long.MAX_VALUE);

7
CodeRank
This code example shows how to use the following methods:getLong
This code example shows how to use the following methods:edit, getBoolean, getLong
    private final static int LAUNCHES_UNTIL_PROMPT = 7;
     
    public static void appLaunched(Context mContext) {
        SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
 
        if (prefs.getBoolean("dontshowagain", false)) { return ; }
         
        SharedPreferences.Editor editor = prefs.edit();
         
        // Increment launch counter 
        long launch_count = prefs.getLong("launch_count", 0) + 1;
        editor.putLong("launch_count", launch_count);
 
        // Get date of first launch 
        Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
        if (date_firstLaunch == 0) {
            date_firstLaunch = System.currentTimeMillis();
            editor.putLong("date_firstlaunch", date_firstLaunch);
        } 
         

8
CodeRank
This code example shows how to use the following methods:getLong
 
    public long getDefaultAssignedUser(){ 
        SharedPreferences sharedPreferences = OpencrxCoreUtils.getPrefs();
 
        if (sharedPreferences != null){
            return sharedPreferences.getLong(PREF_USER_ID, -1);
        }else{ 
            return -1; 
        } 
    } 
 
    protected static SharedPreferences getPrefs() {
        try { 
            Context crxContext = ContextManager.getContext().createPackageContext(OPENCRX_PACKAGE, 0);
            SharedPreferences sharedPreferences = crxContext.getSharedPreferences(PREFS_FILE,
                                            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
            return sharedPreferences;
        } catch (NameNotFoundException e) {
            return null; 
        } 
6
CodeRank
This code example shows how to use the following methods:edit, getLong, getString
 
    private String getIDFromFile(Context ctx) {
        SharedPreferences mSettings = null;
        mSettings = getPreferenceFile();
        mLogging.info(LOGTAG, "Verifying Install Info");
        mUniqueID = mSettings.getString(UNIQUE_KEYID, "");
        if (mUniqueID.length() == 0) {
            // Application First run 
            mLogging.info(LOGTAG,
                    "First Time Running - Generating Unique Install ID"); 
            mIsFirstTimeRunnig = true;
            mIsAValidInstall = true;
            mUniqueID = UUID.randomUUID().toString();
            mInstallTimeStamp = System.currentTimeMillis();
            mTimeStampHash=DigestUtils.shaHex(mUniqueID + Long.toString(mInstallTimeStamp));
            saveToPreferencesFile(mSettings, mUniqueID, mInstallTimeStamp, mTimeStampHash);
            mLogging.info(LOGTAG, "Install Info Saved with Success");
            return mUniqueID;
        } else { 
            mLogging.info(LOGTAG, "Not First Time Running - Validating Install");

6
CodeRank
This code example shows how to use the following methods:edit, getBoolean, getLong
    private final static int DAYS_UNTIL_PROMPT = 3;
    private final static int LAUNCHES_UNTIL_PROMPT = 8;
 
    public static void app_launched(Context context) {
        SharedPreferences prefs = context.getSharedPreferences("apprater", 0);
        if (prefs.getBoolean("dontshowagain", false)) { return; }
         
        SharedPreferences.Editor editor = prefs.edit();
         
        // Increment launch counter 
        long launch_count = prefs.getLong("launch_count", 0) + 1;
        editor.putLong("launch_count", launch_count);
 
        // Get date of first launch 
        Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
        if (date_firstLaunch == 0) {
            date_firstLaunch = System.currentTimeMillis();
            editor.putLong("date_firstlaunch", date_firstLaunch);
        } 
         
7
CodeRank
This code example shows how to use the following methods:getLong, getString

Related SharedPreferences getLong Questions & Answers:

getLong Method Overview
Retrieve a long value from the preferences.
See Code Examples for other Android SharedPreferences Methods: