private boolean loadSharedPreferencesFromFile(File src) { // this should probably be in a thread if it ever gets big boolean res = false; ObjectInputStream input = null; try { input = new ObjectInputStream(new FileInputStream(src)); Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(this).edit(); prefEdit.clear(); // first object is preferences Map<String, ?> entries = (Map<String, ?>) input.readObject(); for (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(); // second object is admin options Editor adminEdit = getSharedPreferences(AdminPreferencesActivity.ADMIN_PREFERENCES, 0).edit(); adminEdit.clear(); // first object is preferences Map<String, ?> adminEntries = (Map<String, ?>) input.readObject(); for (Entry<String, ?> entry : adminEntries.entrySet()) { Object v = entry.getValue(); String key = entry.getKey(); if (v instanceof Boolean) adminEdit.putBoolean(key, ((Boolean) v).booleanValue()); else if (v instanceof Float) adminEdit.putFloat(key, ((Float) v).floatValue()); else if (v instanceof Integer) adminEdit.putInt(key, ((Integer) v).intValue()); else if (v instanceof Long) adminEdit.putLong(key, ((Long) v).longValue()); else if (v instanceof String) adminEdit.putString(key, ((String) v)); } adminEdit.commit(); res = true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } finally { try { if (input != null) { input.close(); } } catch (IOException ex) { ex.printStackTrace(); } } return res; }
@Override protected void onPostExecute(String result) { // TODO Auto-generated method stub super.onPostExecute(result); if (pd != null && pd.isShowing()) pd.dismiss(); if (result != null && result.equals("1")) { Log.d("check", result + "_"); // if(upload!=null) uploadList = db.retriveUpload(); for (Upload up : uploadList) { db.deleteUpload(up); } Editor edit = preference.edit(); edit.putInt("upload", 2); edit.putInt("playMode", 2); edit.putString("activity", null); edit.clear(); edit.commit(); finish(); } else { try { alert.showAlertDialog(home.this, "Error", "Unable to process server", true); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } }
private void clearKeys() { SharedPreferences prefs = parentActivity.getSharedPreferences(ACCOUNT_PREFS_NAME, Context.MODE_PRIVATE); Editor edit = prefs.edit(); edit.clear(); edit.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(); if (id == R.id.action_settings) { return true; } if (id == R.id.action_logout) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String name = sharedPreferences.getString("username", "ab"); Editor editor = sharedPreferences.edit(); Toast.makeText(SearchLoggedInActivity.this, "Goodbye " + name, Toast.LENGTH_LONG).show(); editor.clear(); editor.commit(); Intent intent = new Intent(SearchLoggedInActivity.this, MainActivity.class); startActivity(intent); finish(); } return super.onOptionsItemSelected(item); }
public void saveSelectedContacts() { Editor editor = mSavedSelectedContacts.edit(); editor.clear(); for (String email : mSelectedContacts) { editor.putString(email, getName(email)); } editor.apply(); }
/** * Clear all alarms from the Android shared Preferences * * @return true when successfull, otherwise false */ private boolean unpersistAlarmAll() { final Editor alarmSettingsEditor = this.ctx.getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE).edit(); alarmSettingsEditor.clear(); return alarmSettingsEditor.commit(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { int br = 1; switch (item.getItemId()) { case R.id.menu_settings: Intent i = new Intent(this, UserSettingActivity.class); startActivityForResult(i, RESULT_SETTINGS); break; case R.id.menu_upload: if (global.getLogin() != null) { brands = db.retriveBrand(); for (Brand bra : brands) { if (bra.getBrandStatus().equals("true")) { ++br; } } uploadList = db.retriveUpload(); if (br >= 2) { if (connection.isConnectingToInternet()) { try { new Load().execute(uploadList); } catch (Exception e) { // TODO: handle exception } Editor edit = preference.edit(); edit.putInt("upload", 2); edit.putInt("playMode", 2); edit.clear(); edit.commit(); db.resetTables(MySQLiteHelper.TABLE_NAME); db.resetTables(MySQLiteHelper.server_table); global.setLogin(null); Toast.makeText(home.this, "success", Toast.LENGTH_LONG).show(); finish(); } else { alert.showAlertDialog(home.this, "Warning", "Check your network connection", true); } } else { alert.showAlertDialog(home.this, "Warning", "You need to play atleast two brand", true); } } else { { Constants.name = preference.getString("name", null); Constants.age = preference.getString("age", null); Constants.gender = preference.getString("gender", null); if (Constants.name != null && Constants.age != null && Constants.gender != null) new InsertData().execute(); else alert.showAlertDialog( home.this, "Warning", "You are not logged in and no data to upload", true); } } break; } return true; }
public void clearAll() { pref = context.getSharedPreferences(PREF_NAME, 0); edit = pref.edit(); edit.clear().apply(); pref = context.getSharedPreferences(PREF_MANUALS, 0); edit = pref.edit(); edit.clear().apply(); pref = context.getSharedPreferences(PREF_PLANS, 0); edit = pref.edit(); edit.clear().apply(); pref = context.getSharedPreferences(PREF_AGREEMENTS, 0); edit = pref.edit(); edit.clear().apply(); pref = context.getSharedPreferences(PREF_DOCUMENTS, 0); edit = pref.edit(); edit.clear().apply(); pref = context.getSharedPreferences(PREF_PROCEDURES, 0); edit = pref.edit(); edit.clear().apply(); pref = context.getSharedPreferences(PREF_GUIDELINES, 0); edit = pref.edit(); edit.clear().apply(); }
public void clearNumbers(View view) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); listItems.clear(); adapter.notifyDataSetChanged(); Editor editor = sharedPreferences.edit(); editor.clear(); editor.commit(); }
private void clearSharedPreferenes() { SharedPreferences sharedPreferences = this.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.clear(); editor.commit(); this.finish(); startActivity(this.getIntent()); }
protected void deleteOne() { b = true; mNosearch.setVisibility(View.VISIBLE); mHistoryOne.removeFooterView(mViewFooter); mListOne.clear(); // setAdapterOne(); Editor edit = mSpOne.edit(); edit.clear(); edit.commit(); }
protected void deleteTwo() { mNosearch.setVisibility(View.VISIBLE); mHistoryTwo.removeFooterView(mViewFooter); mListTwo.clear(); mBoolean = true; // setAdapterTwo(); Editor edit = mSpTwo.edit(); edit.clear(); edit.commit(); }
public void saveBookmarks() { SharedPreferences prefs = context.getSharedPreferences("Bookmarks", 0); Editor editor = prefs.edit(); editor.clear(); for (int i = 0; i < bookmarks.size(); i++) { editor.putInt("bookmark" + i, bookmarks.get(i)); } editor.commit(); }
/** Clear session details */ public void logoutUser() { // Clearing all data from Shared Preferences editor.clear(); editor.commit(); Intent i = new Intent(_context, login_activity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); _context.startActivity(i); }
/** * 清空 SharedPreferences 中 Token信息。 * * @param context 应用程序上下文环境 */ public static void clear(Context context) { if (null == context) { return; } SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND); Editor editor = pref.edit(); editor.clear(); editor.commit(); }
@Override public void logoutUser() { editor.clear(); editor.commit(); Intent intent = new Intent(AppUtil.CONTEXT, LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); AppUtil.CONTEXT.startActivity(intent); }
// Clears session details public void logoutUser() { editor.clear(); editor.commit(); // After logout the user is redirected to the login activity and all the other activities are // closed Intent i = new Intent(context, LoginActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Editor editor = prefs.edit(); editor.clear(); editor.commit(); finish(); startActivity(new Intent(this, Setting.class)); }
public void logoutUser() { editor.clear(); editor.commit(); Intent i = new Intent(_context, SignIn.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); _context.startActivity(i); }
/** Clear session details */ public void logoutUser() { // Clearing all data from Shared Preferences editor.clear(); editor.commit(); // After logout redirect user to Login Activity Intent i = new Intent(_context, ProfileActivity.class); // Closing all the Activities i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Add new Flag to start new Activity i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Staring Login Activity _context.startActivity(i); }
private void saveCookiesToPreferences(Context context, DefaultHttpClient client) { final SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME_SUMC_COOKIES, Context.MODE_PRIVATE); final Editor edit = sharedPreferences.edit(); edit.clear(); int i = 0; for (Cookie cookie : client.getCookieStore().getCookies()) { edit.putString(PREFERENCES_COOKIE_NAME + i, cookie.getName()); edit.putString(PREFERENCES_COOKIE_VALUE + i, cookie.getValue()); edit.putString(PREFERENCES_COOKIE_DOMAIN + i, cookie.getDomain()); edit.putString(PREFERENCES_COOKIE_PATH + i, cookie.getPath()); i++; } edit.commit(); }
/** @param 增加 */ public void put(String[] cardNames) { if (cardNames == null || cardNames.length < 1) { // Put为空 = 删除所有 clear(); return; } Editor editor = sharedPreferences.edit(); // 获取编辑器 editor.clear(); StringBuilder strBuilder = new StringBuilder(); strBuilder.append(initFlag); for (int i = 0; i < cardNames.length; i++) { strBuilder.append(cardNames[i].trim() + ","); } // 去掉最后一个逗号 strBuilder.replace(strBuilder.lastIndexOf(","), strBuilder.length(), ""); editor.putString("cardNames", strBuilder.toString().trim()); editor.commit(); }
protected void clearUserProfile() { Context context = getApplicationContext(); SharedPreferences pref = context.getSharedPreferences(PREF_NAME, PREF_MODE); Editor editor = pref.edit(); ; editor.remove(KEY_AGE); editor.remove(KEY_HEIGHT); editor.remove(KEY_WEIGHT); editor.clear(); editor.commit(); mEditAge.setText(null); mEditHeight.setText(null); mEditWeight.setText(null); Toast.makeText(getApplicationContext(), "User profile cleared!", Toast.LENGTH_LONG).show(); }
/** 按键事件监听 */ public boolean onKeyDown(int keyCode, android.view.KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_TAB: // date=tv_time.getText().toString(); String machine = et_input.getText().toString(); if (!Tools.isNull(machine)) { Editor ed = sp_machine_no.edit(); ed.clear(); ed.putString("no", machine); ed.commit(); startActivity(new Intent(mContext, MainAc.class)); } else { Toast.makeText(mContext, "请输入机台号", Toast.LENGTH_LONG); } break; default: break; } return super.onKeyDown(keyCode, event); }
private static void copySettings(SharedPreferences source, SharedPreferences target) { Editor editor = target.edit(); editor.clear(); for (Entry<String, ?> entry : source.getAll().entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof Boolean) { editor.putBoolean(key, (Boolean) value); } else if (value instanceof Float) { editor.putFloat(key, (Float) value); } else if (value instanceof Integer) { editor.putInt(key, (Integer) value); } else if (value instanceof Long) { editor.putLong(key, (Long) value); } else if (value instanceof String) { editor.putString(key, (String) value); } } editor.commit(); }
/** Clear session details */ public void logoutUser() { Pushbots.sharedInstance().setPushEnabled(false); Pushbots.sharedInstance().unRegister(); // Clearing all user data from Shared Preferences editor.clear(); editor.commit(); // After logout redirect user to Login Activity Intent i = new Intent(_context, LogInActivity.class); // Closing all the Activities i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Add new Flag to start new Activity i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Staring Login Activity _context.startActivity(i); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_create: if (isOnline()) { Intent intent = new Intent(this, CreateActivity.class); startActivity(intent); } else { Toast.makeText(this, "Network isn't available!", Toast.LENGTH_LONG).show(); } break; case R.id.menu_logout: sPref = getSharedPreferences(LoginActivity.USER_ID, MODE_PRIVATE); Editor editor = sPref.edit(); editor.clear(); editor.commit(); startActivity(new Intent(this, LoginActivity.class)); finish(); break; default: break; } return super.onOptionsItemSelected(item); }
/** * 清除所有数据 * * @param context * @return 是否成功 */ public static boolean clear(Context context) { SharedPreferences sp = context.getSharedPreferences(SharePreferncesName, Context.MODE_PRIVATE); Editor editor = sp.edit(); editor.clear(); return editor.commit(); }
@Override public void clear() { Editor edit = sharedPrefs.edit(); edit.clear(); edit.commit(); }
public void clearKeys() { SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0); Editor edit = prefs.edit(); edit.clear(); edit.commit(); }