Code example for SharedPreferences

Methods: editgetString

0
		public void onCreate(SQLiteDatabase db) {
			db.execSQL(DATABASE_CREATE);
			 
			// Migrate preference to database if it is set. 
			SharedPreferences settings = mCtx.getSharedPreferences("PasswordActivity", Context.MODE_PRIVATE); 
			String lastFile = settings.getString(LAST_FILENAME, "");
			String lastKey = settings.getString(LAST_KEYFILE,"");
						 
			if ( lastFile.length() > 0 ) {
				ContentValues vals = new ContentValues();
				vals.put(KEY_FILE_FILENAME, lastFile);
				vals.put(KEY_FILE_UPDATED, System.currentTimeMillis());
				 
				if ( lastKey.length() > 0 ) {
					vals.put(KEY_FILE_KEYFILE, lastKey);
				} 
				 
				db.insert(FILE_TABLE, null, vals);
				 
				// Clear old preferences 
				deletePrefs(settings);
				 
			} 
		} 
 
		@Override 
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			// Only one database version so far 
		} 
		 
		private void deletePrefs(SharedPreferences prefs) {
			// We won't worry too much if this fails 
			try { 
				SharedPreferences.Editor editor = prefs.edit();
				editor.remove(LAST_FILENAME);
				editor.remove(LAST_KEYFILE);
				EditorCompat.apply(editor);
			} catch (Exception e) {
				assert(true);