Code example for SharedPreferences

Methods: getBooleangetLong

0
		} 
		// 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);         
	} 
	 
    private void writeLockTime() { 
        writeLockTime(SystemClock.elapsedRealtime());
    } 
 
    private void writeLockTime(long time) {
        mEditor = mPrefs.edit();
        mEditor.putLong("locked_at", time);
        mEditor.commit();       
    } 
 
	protected void setLockEnabled(boolean enabled) {
        mEditor = mPrefs.edit();
        mEditor.putBoolean("lock_enabled", enabled);
        mEditor.commit();        
	} 
 
    protected boolean isLockEnabled() { 
        return mPrefs.getBoolean("lock_enabled", true);       
    }	 
     
    protected void onActivityResult(int requestCode, int resultCode,
            Intent data) {
        super.onActivityResult(requestCode, resultCode, data);