// @TODO this is a sample to get through the database public void buildDummy(SQLiteDatabase db) { // set query to execute String query = "SELECT * FROM Users;"; // set a cursor to run the query Cursor c = db.rawQuery(query, null); // move to the first row c.moveToFirst(); // clear the shared preferences editor.clear(); // set both the shared prefernces and the user elements... editor.putString("name", name = c.getString(1)); editor.putFloat("weight", weight = c.getFloat(2)); editor.putFloat("height", height = c.getFloat(3)); editor.putFloat("BMI", BMI = c.getFloat(4)); editor.putFloat("BMR", BMR = c.getFloat(5)); editor.putFloat("Starting_Weight", start_weight = c.getFloat(6)); editor.putInt("Start_LVL", start_lvl = c.getInt(7)); editor.putFloat("Cal_Needs", cal_needs = c.getFloat(8)); editor.putFloat("Current_Weight", cur_weight = c.getFloat(9)); editor.putInt("Cur_Lvl", cur_lvl = c.getInt(10)); editor.putString("Email", email = c.getString(11)); editor.putString("Phone", phone = c.getString(12)); // commit changes to shared preferences editor.commit(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } if (id == R.id.action_logout) { SharedPreferences userDetails = getSharedPreferences("userdetails", MODE_PRIVATE); SharedPreferences.Editor edit = userDetails.edit(); edit.clear(); edit.putString("username", ""); edit.putString("password", ""); edit.commit(); NetWork.logout(); Intent intent = new Intent(getApplicationContext(), LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); finish(); startActivity(intent); return true; } return super.onOptionsItemSelected(item); }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } if (id == R.id.action_logout) { SharedPreferences preferences = this.getSharedPreferences(LoginActivity.SHARED_DATA, MODE_PRIVATE); SharedPreferences.Editor edit = preferences.edit(); edit.clear(); edit.commit(); Intent intent = new Intent(this, LoginActivity.class); this.startActivity(intent); this.finish(); } return super.onOptionsItemSelected(item); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.left_in, R.anim.left_out); int screenSize = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; if (screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE || screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } setContentView(R.layout.activity_main); if (savedInstanceState == null) { loadSecondActivity(); } TextView tvEmoji = (TextView) findViewById(R.id.tvEmoji); int emoji = getResources().getInteger(R.integer.txt_emoji2); tvEmoji.setText(new String(Character.toChars(emoji))); SharedPreferences shared = getSharedPreferences("SharedKey", MODE_PRIVATE); SharedPreferences.Editor editor = shared.edit(); editor.clear(); editor.remove("modeKey"); editor.commit(); }
public boolean logout() { try { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(App.getAppContext()); List<AbstractMap.SimpleEntry<String, String>> params = new ArrayList<>(); AbstractMap.SimpleEntry<String, String> username = new AbstractMap.SimpleEntry<>("username", preferences.getString("username", "")); AbstractMap.SimpleEntry<String, String> token = new AbstractMap.SimpleEntry<>("token", preferences.getString("token", "")); params.add(username); params.add(token); String response = App.HTMLPOST(App.Prefs().getString("domain", "") + "/API/logout", params); // TODO: Redo, this whole thing is flawed. if (response.equals("Logout successful")) { final SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); return true; } return false; } catch (Exception e) { return false; } }
public static void deleteSharedPreferences( String sharedPreferencesName, String arrayName, Context mContext) { SharedPreferences prefs = mContext.getSharedPreferences(sharedPreferencesName, 0); SharedPreferences.Editor editor = prefs.edit(); editor.clear(); editor.commit(); }
public static <T extends ConfigBase> void Save(T config) { SharedPreferences store = config.getStore(); SharedPreferences.Editor editor = store.edit(); editor.clear(); config.SetValues(editor); editor.commit(); }
public static void removeAllSharedPref(Context context) { SharedPreferences sharedPreferences = context.getSharedPreferences(sharedPrefFileName, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.clear(); editor.commit(); }
public void clearAllPreferences() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(myContext); SharedPreferences.Editor editor = prefs.edit(); editor.clear(); editor.commit(); // important! Don't forget! }
/** * @param c Context * @param file Clear the preferences stored in this file */ public static void clearPreferences(final Context c, final String file) { final SharedPreferences preferences = c.getSharedPreferences(file, Context.MODE_PRIVATE); final SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); }
private void clearCurrentState() { SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences( "logininfo", Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); }
// reset all saved preferences so their default is loaded next time public static void resetAllPrefs(final Context context) { Log.w(TAG, "resetAllPrefs()"); final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences.Editor editor = settings.edit(); editor.clear(); editor.commit(); }
public static void clearAuthTokeCache(Context context) { SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.TUMBLR_CLIENT_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.clear(); editor.commit(); TumblrClientApplication.setClientAsNull(); }
@Override public boolean removeAllCookie() { SharedPreferences.Editor prefsWriter = cookiePrefs.edit(); prefsWriter.clear(); prefsWriter.commit(); cookies.clear(); return true; }
/** 清空数据 */ public void clear() { if (mEditor == null) { mEditor = mSharedPreferences.edit(); } mEditor.clear(); mEditor.apply(); }
private void savedata(String userroll, String pass) { // TODO Auto-generated method stub editor.clear(); editor.putString("roll", userroll); editor.putString("password", pass); editor.putString("remember", "yes"); editor.commit(); }
public void putSharedPreference(Context context, String preferenceName, int val) { SharedPreferences pref = context.getSharedPreferences(preferenceName, 0); // 0 - for private // mode SharedPreferences.Editor editor = pref.edit(); editor.clear(); editor.putInt(preferenceName, val); editor.commit(); }
/** * 清除保存的信息 * * @return 成功返回true,失败返回false */ public static boolean clearSharedPreferences() { if (mEditor == null) { return false; } else { mEditor.clear().apply(); return true; } }
@Override public void onBackPressed() { // super.onBackPressed(); editor2.clear(); editor2.commit(); Intent intent = new Intent(this, MainActivity.class); startActivity(intent); }
public void clearData() { try { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor e = prefs.edit(); e.clear().commit(); } catch (Exception e) { e.printStackTrace(); } }
private void update() { List<Todo> currentTodos = getAll(); SharedPreferences.Editor editor = prefs.edit(); editor.clear(); for (int i = 0; i < currentTodos.size(); i++) { editor.putString(INDEX_PREFIX + i, currentTodos.get(i).value); } editor.apply(); }
public static boolean loadSharedPreferencesFromFile(File src, Context context) { boolean res = false; ObjectInputStream input = null; try { if (!src.getParentFile().exists()) { src.getParentFile().mkdirs(); src.createNewFile(); } input = new ObjectInputStream(new FileInputStream(src)); SharedPreferences.Editor prefEdit = context .getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .edit(); prefEdit.clear(); @SuppressWarnings("unchecked") Map<String, ?> entries = (Map<String, ?>) input.readObject(); for (Map.Entry<String, ?> entry : entries.entrySet()) { Object v = entry.getValue(); String key = entry.getKey(); if (v instanceof Boolean) { prefEdit.putBoolean(key, ((Boolean) v).booleanValue()); } else if (v instanceof Float) { prefEdit.putFloat(key, ((Float) v).floatValue()); } else if (v instanceof Integer) { prefEdit.putInt(key, ((Integer) v).intValue()); } else if (v instanceof Long) { prefEdit.putLong(key, ((Long) v).longValue()); } else if (v instanceof String) { prefEdit.putString(key, ((String) v)); } } prefEdit.commit(); res = true; } catch (Exception e) { } finally { try { if (input != null) { input.close(); } } catch (Exception e) { } } return res; }
public void logout() { SharedPreferences pref = this.application.getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.clear(); editor.apply(); this.session.close(); }
@Override public SharedPreferences.Editor clear() { SharedPreferences sharedPreferences = context.getSharedPreferences(SharedPreferencesName, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.clear(); editor.commit(); return editor; }
public void clearPrefs(ContextWrapper cw) { if (mPrefs == null) { mPrefs = cw.getSharedPreferences(IParkingConstants.PREFS, Context.MODE_WORLD_READABLE); } SharedPreferences.Editor editor = mPrefs.edit(); editor.clear(); editor.commit(); }
public void saveFiredEvents(Set<String> firedEvents) { SharedPreferences settings = context.getApplicationContext().getSharedPreferences(FIRED_EVENTS_KEY, 0); SharedPreferences.Editor editor = settings.edit(); editor.clear(); for (String name : firedEvents) { editor.putString(name, ""); } editor.commit(); }
public static void clearSharedPreference(Context context) { SharedPreferences preferences = context.getSharedPreferences( context.getResources().getString(R.string.account_type), Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); }
/* package */ void clearPreferences() { // Will clear distinct_ids, superProperties, // and waiting People Analytics properties. Will have no effect // on messages already queued to send with AnalyticsMessages. SharedPreferences.Editor prefsEdit = mStoredPreferences.edit(); prefsEdit.clear().commit(); readSuperProperties(); readIdentities(); }
public void onClick(View v) { SharedPreferences.Editor preferencesEditor = favoritespref.edit(); preferencesEditor.clear(); preferencesEditor.apply(); arrayIndex = 0; // head.removeAllViews(); favoritespref = getSharedPreferences("favorites", MODE_PRIVATE); favorites = favoritespref.getAll().keySet().toArray(new String[0]); genView(favorites); }
public void ClearPreferences() { Iterator it = mUpdatedHashMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); SharedPreferences pref = mContext.getSharedPreferences(pair.getKey().toString(), Context.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putBoolean(Constants.kmsPrefIsUpdated, false); editor.clear(); editor.commit(); } }