本文整理了Java中android.app.Activity.getSharedPreferences()
方法的一些代码示例,展示了Activity.getSharedPreferences()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.getSharedPreferences()
方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:getSharedPreferences
暂无
代码示例来源:origin: huburt-Hu/NewbieGuide
sp = activity.getSharedPreferences(NewbieGuide.TAG, Activity.MODE_PRIVATE);
代码示例来源:origin: avjinder/Minimal-Todo
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
PreferenceKeys preferenceKeys = new PreferenceKeys(getResources());
if (key.equals(preferenceKeys.night_mode_pref_key)) {
SharedPreferences themePreferences = getActivity().getSharedPreferences(MainFragment.THEME_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor themeEditor = themePreferences.edit();
//We tell our MainLayout to recreate itself because mode has changed
themeEditor.putBoolean(MainFragment.RECREATE_ACTIVITY, true);
CheckBoxPreference checkBoxPreference = (CheckBoxPreference) findPreference(preferenceKeys.night_mode_pref_key);
if (checkBoxPreference.isChecked()) {
//Comment out this line if not using Google Analytics
app.send(this, "Settings", "Night Mode used");
themeEditor.putString(MainFragment.THEME_SAVED, MainFragment.DARKTHEME);
} else {
themeEditor.putString(MainFragment.THEME_SAVED, MainFragment.LIGHTTHEME);
}
themeEditor.apply();
getActivity().recreate();
}
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Test
public void testinstallationIdExist() {
SharedPreferences sp = activity.getSharedPreferences(ClientContext.SHARED_PREFERENCES,
Context.MODE_PRIVATE);
// random UUID
String installationId = "2d9a130e-1c3b-40c7-8953-c7c4aea3d6fa";
sp.edit().putString("installation_id", installationId).commit();
assertEquals(installationId, ClientContext.getInstallationId(activity));
}
代码示例来源:origin: com.uphyca/android-junit4-robolectric
/**
* @param name
* @param mode
* @return
* @see android.content.ContextWrapper#getSharedPreferences(java.lang.String,
* int)
*/
public SharedPreferences getSharedPreferences(String name,
int mode) {
return mActivity.getSharedPreferences(name, mode);
}
代码示例来源:origin: stackoverflow.com
public SessionManagment(Activity mContextActivity){
// this.contextActivity = mContext;
sharedPrefSession = mContextActivity.getSharedPreferences(
Constants.SHARED_PREFERANCES_LIGHT_TIGER_SESSION_FILE_NAME,
Context.MODE_PRIVATE);
}//enden constructor
代码示例来源:origin: stackoverflow.com
@TransfuseModule
class Module{
@Provides @Named("the_shared_prefs")
public SharedPreferences build(Activity activity){
return activity.getSharedPreferences("the_shared_prefs", Context.MODE_PRIVATE)
}
}
代码示例来源:origin: stackoverflow.com
Activity activity = mActivityRule.getActivity();
SharedPreferences prefs = activity.getSharedPreferences("current.user", Context.MODE_PRIVATE);
assertTrue(prefs.getBoolean("IsLoggedIn", false));
代码示例来源:origin: stackoverflow.com
Button btn = (Button)view.findViewById(R.id.btnSave);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Activity myActivity=(Activity)(v.getContext()); // all views have a reference to their context
SharedPreferences prefs =myActivity.getSharedPreferences(
"com.example.app", Context.MODE_PRIVATE);
}
});
代码示例来源:origin: googlesamples/android-DeviceOwner
/**
* Loads the package name from SharedPreferences.
*
* @param activity The activity
* @return The package name of the launcher currently set as preferred, or null if there is no
* preferred launcher.
*/
private static String loadPersistentPreferredLauncher(Activity activity) {
return activity.getSharedPreferences(PREFS_DEVICE_OWNER, Context.MODE_PRIVATE)
.getString(PREF_LAUNCHER, null);
}
代码示例来源:origin: adrian/upm-android
public static void setDatabaseFileName(String dbFileName, Activity activity) {
SharedPreferences settings = activity.getSharedPreferences(Prefs.PREFS_NAME, Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PREFS_DB_FILE_NAME, dbFileName);
editor.commit();
}
代码示例来源:origin: freshplanet/ANE-Push-Notification
private void storeUrl(Activity act, String url) {
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = act.getSharedPreferences(Extension.PREFS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString(Extension.PREFS_KEY, url);
// Commit the edits!
editor.commit();
}
代码示例来源:origin: tvbarthel/ChaseWhisplyProject
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof BonusFragment.Listener) {
mListener = (BonusFragment.Listener) activity;
mPlayerProfile = new PlayerProfile(activity.getSharedPreferences(
PlayerProfile.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE));
} else {
throw new ClassCastException(activity.toString()
+ " must implement BonusFragment.Listener");
}
}
代码示例来源:origin: tvbarthel/ChaseWhisplyProject
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof ProfileFragment.Listener) {
mListener = (ProfileFragment.Listener) activity;
mPlayerProfile = new PlayerProfile(activity.getSharedPreferences(
PlayerProfile.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE));
} else {
throw new ClassCastException(activity.toString()
+ " must implement ProfileFragment.Listener");
}
}
代码示例来源:origin: tvbarthel/ChaseWhisplyProject
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof GameScoreFragment.Listener) {
mListener = (GameModeChooserFragment.Listener) activity;
mPlayerProfile = new PlayerProfile(activity.getSharedPreferences(
PlayerProfile.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE));
} else {
throw new ClassCastException(activity.toString()
+ " must implement GameModeChooserFragment.Listener");
}
}
代码示例来源:origin: shinezejian/emotionkeyboard
/**
* 外部静态调用
* @param activity
* @return
*/
public static EmotionKeyboard with(Activity activity) {
EmotionKeyboard emotionInputDetector = new EmotionKeyboard();
emotionInputDetector.mActivity = activity;
emotionInputDetector.mInputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
emotionInputDetector.sp = activity.getSharedPreferences(SHARE_PREFERENCE_NAME, Context.MODE_PRIVATE);
return emotionInputDetector;
}
代码示例来源:origin: tvbarthel/ChaseWhisplyProject
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mPlayerProfile = new PlayerProfile(activity.getSharedPreferences(
PlayerProfile.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE));
if (activity instanceof GameModeFragment.Listener) {
//show play button
mListener = (GameModeFragment.Listener) activity;
}
}
代码示例来源:origin: tvbarthel/ChaseWhisplyProject
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof GameModeDetailsFragment.Listener) {
mListener = (GameModeDetailsFragment.Listener) activity;
mPlayerProfile = new PlayerProfile(activity.getSharedPreferences(
PlayerProfile.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE));
} else {
throw new ClassCastException(activity.toString()
+ " must implemenet GameModeDetailsFragment.Listener");
}
}
代码示例来源:origin: doc-rj/smartcard-reader
public void onResume() {
setShareIntent();
SharedPreferences ss = mActivity.getSharedPreferences("prefs", Context.MODE_PRIVATE);
mMsgPos = ss.getInt("msg_pos", 0);
// this delay is a bit hacky; would be better to extend ListView
// and override onLayout()
mHandler.postDelayed(new Runnable() {
public void run() {
smoothScrollToPosition();
}
}, 50L);
}
代码示例来源:origin: gigabytedevelopers/FireFiles
public static AppRate with(Activity activity) {
AppRate instance = new AppRate(activity);
instance.text = "Enjoying the app? Spread the word!";//activity.getString(R.string.dra_rate_app);
instance.settings = activity.getSharedPreferences(PREFS_NAME, 0);
instance.editor = instance.settings.edit();
return instance;
}
代码示例来源:origin: adrian/upm-android
public static String getSyncMethod(Activity activity) {
UPMApplication app = (UPMApplication) activity.getApplication();
String remoteHTTPLocation = app.getPasswordDatabase().getDbOptions().getRemoteLocation();
SharedPreferences settings = activity.getSharedPreferences(Prefs.PREFS_NAME, Activity.MODE_PRIVATE);
return getSyncMethod(settings, remoteHTTPLocation);
}
内容来源于网络,如有侵权,请联系作者删除!