android.os.Bundle.getBoolean()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(244)

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

Bundle.getBoolean介绍

暂无

代码示例

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

Bundle extras = getIntent().getExtras();
if (extras != null) {
  boolean isNew = extras.getBoolean("isNewItem", false);
  if (isNew) {
    // Do something
  } else {
    // Do something else
  }
}

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

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
 super.onRestoreInstanceState(savedInstanceState);
 // Restore UI state from the savedInstanceState.
 // This bundle has also been passed to onCreate.
 boolean myBoolean = savedInstanceState.getBoolean("MyBoolean");
 double myDouble = savedInstanceState.getDouble("myDouble");
 int myInt = savedInstanceState.getInt("MyInt");
 String myString = savedInstanceState.getString("MyString");
}

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

// You can be pretty confident that the intent will not be null here.
Intent intent = getIntent();

// Get the extras (if there are any)
Bundle extras = intent.getExtras();
if (extras != null) {
  if (extras.containsKey("isNewItem")) {
    boolean isNew = extras.getBoolean("isNewItem", false);

    // TODO: Do something with the value of isNew.
  }
}

代码示例来源:origin: crazycodeboy/TakePhoto

@Override
public void onCreate(Bundle savedInstanceState) {
  if (savedInstanceState != null) {
    cropOptions = (CropOptions) savedInstanceState.getSerializable("cropOptions");
    takePhotoOptions = (TakePhotoOptions) savedInstanceState.getSerializable("takePhotoOptions");
    showCompressDialog = savedInstanceState.getBoolean("showCompressDialog");
    outPutUri = savedInstanceState.getParcelable("outPutUri");
    tempUri = savedInstanceState.getParcelable("tempUri");
    compressConfig = (CompressConfig) savedInstanceState.getSerializable("compressConfig");
  }
}

代码示例来源:origin: Bearded-Hen/Android-Bootstrap

@Override public void onRestoreInstanceState(Parcelable state) {
  if (state instanceof Bundle) {
    Bundle bundle = (Bundle) state;
    this.roundedCorners = bundle.getBoolean(RoundableView.KEY);
    state = bundle.getParcelable(TAG);
  }
  super.onRestoreInstanceState(state);
}

代码示例来源:origin: naman14/Timber

private void onPreferencesUpdate(Bundle extras) {
  mShowAlbumArtOnLockscreen = extras.getBoolean("lockscreen", mShowAlbumArtOnLockscreen);
  mActivateXTrackSelector = extras.getBoolean("xtrack",mActivateXTrackSelector);
  LastfmUserSession session = LastfmUserSession.getSession(this);
  session.mToken = extras.getString("lf_token", session.mToken);
  session.mUsername = extras.getString("lf_user", session.mUsername);
  if ("logout".equals(session.mToken)) {
    session.mToken = null;
    session.mUsername = null;
  }
  notifyChange(META_CHANGED);
}

代码示例来源:origin: Bearded-Hen/Android-Bootstrap

@Override public void onRestoreInstanceState(Parcelable state) {
  if (state instanceof Bundle) {
    Bundle bundle = (Bundle) state;
    this.roundedCorners = bundle.getBoolean(RoundableView.KEY);
    this.showOutline = bundle.getBoolean(OutlineableView.KEY);
    this.bootstrapSize = bundle.getFloat(BootstrapSizeView.KEY);
    Serializable direction = bundle.getSerializable(KEY_DIRECTION);
    if (direction instanceof ExpandDirection) {
      expandDirection = (ExpandDirection) direction;
    }
  }
  super.onRestoreInstanceState(state);
}

代码示例来源:origin: smuyyh/BookReader

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
  if ((state != null) && state.containsKey(BUNDLE_POSITION)
      && state.containsKey(BUNDLE_BOOK)) {
    mPosition = state.getInt(BUNDLE_POSITION);
    mBook = (Book) state.getSerializable(BUNDLE_BOOK);
    mEpubFileName = state.getString(BUNDLE_EPUB_FILE_NAME);
    mIsSmilAvailable = state.getBoolean(BUNDLE_IS_SMIL_AVAILABLE);
  }
  return super.onCreateView(inflater, container, state);
}

代码示例来源:origin: zhihu/Matisse

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
  Context context = mContext.get();
  if (context == null) {
    return null;
  }
  Album album = args.getParcelable(ARGS_ALBUM);
  if (album == null) {
    return null;
  }
  return AlbumMediaLoader.newInstance(context, album,
      album.isAll() && args.getBoolean(ARGS_ENABLE_CAPTURE, false));
}

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

@Implementation(minSdk = LOLLIPOP)
protected boolean hasUserRestriction(String restrictionKey, UserHandle userHandle) {
 Bundle bundle = userRestrictions.get(userHandle.getIdentifier());
 return bundle != null && bundle.getBoolean(restrictionKey);
}

代码示例来源:origin: Bearded-Hen/Android-Bootstrap

@Override public void onRestoreInstanceState(Parcelable state) {
  if (state instanceof Bundle) {
    Bundle bundle = (Bundle) state;
    this.roundable = bundle.getBoolean(RoundableView.KEY);
    Serializable heading = bundle.getSerializable(BootstrapHeading.KEY);
    if (heading instanceof BootstrapHeading) {
      bootstrapHeading = (BootstrapHeading) heading;
    }
    state = bundle.getParcelable(TAG);
  }
  super.onRestoreInstanceState(state);
  updateBootstrapState();
}

代码示例来源:origin: commonsguy/cw-omnibus

private RestrictionEntry buildBooleanRestriction(Context ctxt,
                         Bundle current) {
 RestrictionEntry entry=
   new RestrictionEntry(RESTRICTION_BOOLEAN,
              current.getBoolean(RESTRICTION_BOOLEAN,
                       false));
 entry.setTitle(ctxt.getString(R.string.boolean_restriction_title));
 entry.setDescription(ctxt.getString(R.string.boolean_restriction_desc));
 return(entry);
}

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

public boolean usesChronometer() {
 return RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.N
   ? realNotification.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER)
   : findView(applyContentView(), "chronometer").getVisibility() == View.VISIBLE;
}

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

public boolean isWhenShown() {
 return RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.N
   ? realNotification.extras.getBoolean(Notification.EXTRA_SHOW_WHEN)
   : findView(applyContentView(), "chronometer").getVisibility() == View.VISIBLE
   || findView(applyContentView(), "time").getVisibility() == View.VISIBLE;
}

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

public boolean isIndeterminate() {
 return RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.N
   ? realNotification.extras.getBoolean(Notification.EXTRA_PROGRESS_INDETERMINATE)
   : getProgressBar_PreN().isIndeterminate();
}

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

@Test
public void getBoolean() {
 bundle.putBoolean("foo", true);
 assertThat(bundle.getBoolean("foo")).isTrue();
 assertThat(bundle.getBoolean("bar")).isFalse();
 assertThat(bundle.getBoolean("bar", true)).isTrue();
}

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

@Test
@Config(minSdk = LOLLIPOP)
public void addUserRestrictionShouldWorkAsIntendedForProfileOwner() {
 // GIVEN a user restriction to set
 String restrictionKey = "restriction key";
 // GIVEN the caller is the profile owner
 shadowOf(devicePolicyManager).setProfileOwner(testComponent);
 // WHEN DevicePolicyManager#addUserRestriction is called with the key
 devicePolicyManager.addUserRestriction(testComponent, restrictionKey);
 // THEN the restriction should be set for the current user
 Bundle restrictions = userManager.getUserRestrictions();
 assertThat(restrictions.getBoolean(restrictionKey)).isTrue();
}

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

@Test
@Config(minSdk = LOLLIPOP)
public void addUserRestrictionShouldWorkAsIntendedForDeviceOwner() {
 // GIVEN a user restriction to set
 String restrictionKey = "restriction key";
 // GIVEN the caller is the device owner
 shadowOf(devicePolicyManager).setDeviceOwner(testComponent);
 // WHEN DevicePolicyManager#addUserRestriction is called with the key
 devicePolicyManager.addUserRestriction(testComponent, restrictionKey);
 // THEN the restriction should be set for the current user
 Bundle restrictions = userManager.getUserRestrictions();
 assertThat(restrictions.getBoolean(restrictionKey)).isTrue();
}

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

@Test
@Config(minSdk = LOLLIPOP)
public void clearUserRestrictionShouldWorkAsIntendedForActiveAdmins() {
 // GIVEN the caller is the device owner, and thus an active admin
 shadowOf(devicePolicyManager).setDeviceOwner(testComponent);
 // GIVEN a user restriction has set
 String restrictionKey = "restriction key";
 devicePolicyManager.addUserRestriction(testComponent, restrictionKey);
 // WHEN DevicePolicyManager#clearUserRestriction is called with the key
 devicePolicyManager.clearUserRestriction(testComponent, restrictionKey);
 // THEN the restriction should be cleared for the current user
 Bundle restrictions = userManager.getUserRestrictions();
 assertThat(restrictions.getBoolean(restrictionKey)).isFalse();
}

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

@Test
public void savesInstanceState() {
 final LoginFragment fragment = new LoginFragment();
 final SupportFragmentController<LoginFragment> controller =
   SupportFragmentController.of(fragment, LoginActivity.class);
 controller.create().start().resume().visible();
 LoginActivity activity = (LoginActivity) controller.get().getActivity();
 Bundle expectedState = new Bundle();
 expectedState.putBoolean("isRestored", true);
 activity.setState(expectedState);
 final Bundle savedInstanceState = new Bundle();
 controller.saveInstanceState(savedInstanceState);
 assertThat(savedInstanceState.getBoolean("isRestored")).isTrue();
}

相关文章

Bundle类方法