android.app.Activity.getPreferences()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(243)

本文整理了Java中android.app.Activity.getPreferences()方法的一些代码示例,展示了Activity.getPreferences()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.getPreferences()方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:getPreferences

Activity.getPreferences介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldGiveSharedPreferences() throws Exception {
 Activity activity = Robolectric.setupActivity(Activity.class);
 SharedPreferences preferences = activity.getPreferences(Context.MODE_PRIVATE);
 assertNotNull(preferences);
 preferences.edit().putString("foo", "bar").commit();
 assertThat(activity.getPreferences(Context.MODE_PRIVATE).getString("foo", null)).isEqualTo("bar");
}

代码示例来源:origin: iqiyi/Neptune

@Override
public android.content.SharedPreferences getPreferences(int int0) {
  return mOriginActivity.getPreferences(int0);
}

代码示例来源:origin: com.uphyca/android-junit4-robolectric

/**
 * @param mode
 * @return
 * @see android.app.Activity#getPreferences(int)
 */
public SharedPreferences getPreferences(int mode) {
  return mActivity.getPreferences(mode);
}

代码示例来源:origin: Sparker0i/Weather

public Preferences(Activity activity) {
  prefs = activity.getPreferences(Activity.MODE_PRIVATE);
}

代码示例来源:origin: stackoverflow.com

public void broadcastIntent(View v){
  Activity activity = (Activity) view.getContext()
  SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE);
  SharedPreferences.Editor editor = sharedPref.edit();
  editor.putString("xx",x);
  editor.commit();
  Intent i=new Intent("android.intent.action.AIRPLANE_MODE");
  sendBroadcast(i);
}

代码示例来源:origin: jareddlc/OpenFit

public void onClick(DialogInterface dialog, int index) {
    // Store the answer in SharedPreferences
    SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putBoolean( OpenFitActivity.OpenFitFragment.PREFERENCE_SKIP_CHANGELOG_KEY,
              dontShowAgain.isChecked());
    editor.apply();
  }
});

代码示例来源:origin: CloudRail/cloudrail-si-android-sdk

void storePersistent() {
    SharedPreferences sharedPreferences = context.getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();

    editor.putString("dropboxPersistent", dropbox.get().saveAsString());
    editor.putString("boxPersistent", box.get().saveAsString());
    editor.putString("googledrivePersistent", googledrive.get().saveAsString());
    editor.putString("onedrivePersistent", onedrive.get().saveAsString());
    editor.putString("onedrivebusinessPersistent", googledrive.get().saveAsString());
    editor.putString("egnytePersistent", onedrive.get().saveAsString());
    editor.apply();
  }
}

代码示例来源:origin: dsolonenko/financisto

public static String checkVersionAndShowWhatsNewIfNeeded(Activity activity) {
  try {
    PackageInfo info = Utils.getPackageInfo(activity);
    SharedPreferences preferences = activity.getPreferences(0); 
    int newVersionCode = info.versionCode;
    int oldVersionCode = preferences.getInt("versionCode", -1);
    if (newVersionCode > oldVersionCode) {
      preferences.edit().putInt("versionCode", newVersionCode).commit();
      showWhatsNew(activity);
    }
    return "v. "+info.versionName;
  } catch(Exception ex) { 
    return "Free";
  }
}

代码示例来源:origin: marcoRS/rxjava-essentials

private Observable<AppInfo> getApps() {
  return Observable.create(subscriber -> {
   List<AppInfo> apps = new ArrayList<>();

   SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
   Type appInfoType = new TypeToken<List<AppInfo>>() {
   }.getType();
   String serializedApps = sharedPref.getString("APPS", "");
   if (!"".equals(serializedApps)) {
    apps = new Gson().fromJson(serializedApps, appInfoType);
   }

   for (AppInfo app : apps) {
    subscriber.onNext(app);
   }
   subscriber.onCompleted();
  });
 }
}

代码示例来源:origin: posm/OpenMapKitAndroid

public static void addToMap(Activity activity, MapView mapView) throws IOException, JSONException {
  /**
   * Deal with SharedPreferences. Use it if we haven't explicitly loaded. Set it if we have.
   */
  SharedPreferences preferences = activity.getPreferences(Context.MODE_PRIVATE);
  if (fpGeoJson == null) {
    String previousFpGeoJsonPath = preferences.getString(PREVIOUS_FP_FILE_PATH, null);
    if (previousFpGeoJsonPath == null) return;
    load(new File(previousFpGeoJsonPath));
  } else {
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(PREVIOUS_FP_FILE_PATH, fpGeoJson.getAbsolutePath());
    editor.apply();
  }
  if (atlas == null) return;
  atlas.setActivity(activity);
  atlas.setupMapView(mapView);
}

代码示例来源:origin: marcoRS/rxjava-essentials

private void storeList(List<AppInfo> appInfos) {
 ApplicationsList.getInstance().setList(appInfos);
 Schedulers.io().createWorker().schedule(() -> {
  SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
  Type appInfoType = new TypeToken<List<AppInfo>>() {
  }.getType();
  sharedPref.edit().putString("APPS", new Gson().toJson(appInfos, appInfoType)).apply();
 });
}

代码示例来源:origin: martino2k6/StoreBox

prefs = ((Activity) context).getPreferences(
    preferencesMode.value());
break;

代码示例来源:origin: jareddlc/OpenFit

private void showChangelog(){
  SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
  // Check if the changelog has to be skipped (ie "Don't show again" has been checked)
  boolean skipChangelog = sharedPref.getBoolean(PREFERENCE_SKIP_CHANGELOG_KEY, false);
  // Get versionCode numbers of the app (current and last)
  int lastVersion = sharedPref.getInt(PREFERENCE_LAST_VERSION_KEY, 0);
  int thisVersion = BuildConfig.VERSION_CODE;
  // Reinit skipChangelog if the app has been updated since last start (or first start)
  if(thisVersion != lastVersion){
    SharedPreferences.Editor sharedPrefEditor = sharedPref.edit();
    // Reinitialize the skipChangelog preference
    skipChangelog = false;
    sharedPrefEditor.putBoolean(PREFERENCE_SKIP_CHANGELOG_KEY, false);
    // Set last version
    sharedPrefEditor.putInt(PREFERENCE_LAST_VERSION_KEY, thisVersion);
    sharedPrefEditor.apply();
  }
  if(!skipChangelog) {
    // load news
    DialogNews d = new DialogNews();
    d.show(getFragmentManager(), getString(R.string.dialog_title_news));
  }
}

代码示例来源:origin: CloudRail/cloudrail-si-android-sdk

void prepare(Activity context) {
  this.context = context;
  CloudRail.setAppKey(CLOUDRAIL_LICENSE_KEY);
  this.initDropbox();
  this.initBox();
  this.initGoogleDrive();
  this.initOneDrive();
  this.initOneDriveBusiness();
  this.initEgnyte();
  SharedPreferences sharedPreferences = context.getPreferences(Context.MODE_PRIVATE);
  try {
    String persistent = sharedPreferences.getString("dropboxPersistent", null);
    if (persistent != null) dropbox.get().loadAsString(persistent);
    persistent = sharedPreferences.getString("boxPersistent", null);
    if (persistent != null) box.get().loadAsString(persistent);
    persistent = sharedPreferences.getString("googledrivePersistent", null);
    if (persistent != null) googledrive.get().loadAsString(persistent);
    persistent = sharedPreferences.getString("onedrivePersistent", null);
    if (persistent != null) onedrive.get().loadAsString(persistent);
    persistent = sharedPreferences.getString("onedrivebusinessPersistent", null);
    if (persistent != null) onedrivebusiness.get().loadAsString(persistent);
    persistent = sharedPreferences.getString("egnytePersistent", null);
    if (persistent != null) egnyte.get().loadAsString(persistent);
  } catch (ParseException e) {}
}

代码示例来源:origin: JBossOutreach/lead-management-android

final SharedPreferences sharedPref = mActivity.getPreferences(Context.MODE_PRIVATE);
final String currentServer = sharedPref.getString(getString(R.string.saved_server_ip), "https://github.com/jboss-outreach");
final EditTextPreference mPreference = (EditTextPreference) findPreference("server_location");

相关文章

Activity类方法