android.os.Bundle类的使用及代码示例

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

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

Bundle介绍

[英]For testing use only
[中]仅供测试使用

代码示例

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

Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putString(key, value);
mIntent.putExtras(mBundle);

代码示例来源: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

public static MyFragment newInstance(int someInt) {
  MyFragment myFragment = new MyFragment();

  Bundle args = new Bundle();
  args.putInt("someInt", someInt);
  myFragment.setArguments(args);

  return myFragment;
}

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

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
 super.onSaveInstanceState(savedInstanceState);
 // Save UI state changes to the savedInstanceState.
 // This bundle will be passed to onCreate if the process is
 // killed and restarted.
 savedInstanceState.putBoolean("MyBoolean", true);
 savedInstanceState.putDouble("myDouble", 1.9);
 savedInstanceState.putInt("MyInt", 1);
 savedInstanceState.putString("MyString", "Welcome back to Android");
 // etc.
}

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

Bundle bundle = getIntent().getExtras();
int value = bundle.getInt("some_key");
String value2 = bundle.getString("some_other_key");

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

@Override
public RemoteViews getViewAt(int position) {
 RemoteViews row=
   new RemoteViews(ctxt.getPackageName(), R.layout.row);
 row.setTextViewText(android.R.id.text1, items[position]);
 Intent i=new Intent();
 Bundle extras=new Bundle();
 extras.putString(WidgetProvider.EXTRA_WORD, items[position]);
 extras.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
 i.putExtras(extras);
 row.setOnClickFillInIntent(android.R.id.text1, i);
 return(row);
}

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

@Test
public void testBundleExtra() throws Exception {
 Intent intent = new Intent();
 Bundle bundle = new Bundle();
 bundle.putInt("bar", 5);
 assertSame(intent, intent.putExtra("foo", bundle));
 assertEquals(5, intent.getBundleExtra("foo").getInt("bar"));
}

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

@Test
public void withIntent() {
 final LoginFragment fragment = new LoginFragment();
 Intent intent = new Intent("test_action");
 intent.putExtra("test_key", "test_value");
 SupportFragmentController<LoginFragment> controller =
   SupportFragmentController.of(fragment, LoginActivity.class, intent).create();
 Intent intentInFragment = controller.get().getActivity().getIntent();
 assertThat(intentInFragment.getAction()).isEqualTo("test_action");
 assertThat(intentInFragment.getExtras().getString("test_key")).isEqualTo("test_value");
}

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

@Test
public void startActivities_withBundle_shouldStartAllActivities() {
 activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
 final Intent view = new Intent(Intent.ACTION_VIEW);
 final Intent pick = new Intent(Intent.ACTION_PICK);
 activity.startActivities(new Intent[] {view, pick}, new Bundle());
 assertThat(shadowOf(activity).getNextStartedActivity()).isEqualTo(pick);
 assertThat(shadowOf(activity).getNextStartedActivity()).isEqualTo(view);
}

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

CustomListing currentListing = new CustomListing();
Intent i = new Intent();
Bundle b = new Bundle();
b.putParcelable(Constants.CUSTOM_LISTING, currentListing);
i.putExtras(b);
i.setClass(this, SearchDetailsActivity.class);
startActivity(i);

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

Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);

代码示例来源:origin: bumptech/glide

@Before
public void setUp() throws PackageManager.NameNotFoundException {
 MockitoAnnotations.initMocks(this);
 applicationInfo = new ApplicationInfo();
 applicationInfo.metaData = new Bundle();
 String packageName = "com.bumptech.test";
 when(context.getPackageName()).thenReturn(packageName);
 PackageManager pm = mock(PackageManager.class);
 when(pm.getApplicationInfo(eq(packageName), eq(PackageManager.GET_META_DATA)))
   .thenReturn(applicationInfo);
 when(context.getPackageManager()).thenReturn(pm);
 parser = new ManifestParser(context);
}

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

@Test
public void startActivities_withBundle_shouldStartAllActivities() {
 final Intent view = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 final Intent pick = new Intent(Intent.ACTION_PICK).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 contextWrapper.startActivities(new Intent[] {view, pick}, new Bundle());
 assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isEqualTo(pick);
 assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isEqualTo(view);
}

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

Bundle bundle = new Bundle();
bundle.putString("edttext", "From Activity");
// set Fragmentclass Arguments
Fragmentclass fragobj = new Fragmentclass();
fragobj.setArguments(bundle);

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

@Test
public void shouldValidateSyncExtras() {
 Bundle bundle = new Bundle();
 bundle.putString("foo", "strings");
 bundle.putLong("long", 10L);
 bundle.putDouble("double", 10.0d);
 bundle.putFloat("float", 10.0f);
 bundle.putInt("int", 10);
 bundle.putParcelable("account", a);
 ContentResolver.validateSyncExtrasBundle(bundle);
}

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

public class QueryService extends IntentService {
  protected void onHandleIntent(Intent intent) {
    final ResultReceiver receiver = intent.getParcelableExtra("receiver");
    String command = intent.getStringExtra("command");
    Bundle b = new Bundle();
    if(command.equals("query") {
      receiver.send(STATUS_RUNNING, Bundle.EMPTY);
      try {
        // get some data or something           
        b.putParcelableArrayList("results", results);
        receiver.send(STATUS_FINISHED, b)
      } catch(Exception e) {
        b.putString(Intent.EXTRA_TEXT, e.toString());
        receiver.send(STATUS_ERROR, b);
      }    
    }
  }
}

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

Bundle newExtras = new Bundle();
if (mCropValue.equals("circle")) {
  newExtras.putString("circleCrop", "true");
}
if (mSaveUri != null) {
  newExtras.putParcelable(MediaStore.EXTRA_OUTPUT, mSaveUri);
} else {
  newExtras.putBoolean("return-data", true);
}

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

@Override
public Parcelable onSaveInstanceState() {
  Bundle bundle = new Bundle();
  bundle.putString("stringState", stringState);
  bundle.putParcelable("beanState", beanState);
  return bundle;
}

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

public static final AlertFragment newInstance(int title, String message)
{
  AlertFragment f = new AlertFragment();
  Bundle bdl = new Bundle(2);
  bdl.putInt(EXTRA_TITLE, title);
  bdl.putString(EXTRA_MESSAGE, message);
  f.setArguments(bdl);
  return f;
}

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

@Test
public void getExtras_shouldReturnExtras() {
 Bundle extras = new Bundle();
 extras.putString("Foo", "Bar");
 cursor.setExtras(extras);
 assertThat(cursor.getExtras()).isEqualTo(extras);
 assertThat(cursor.getExtras().getString("Foo")).isEqualTo("Bar");
}

相关文章

Bundle类方法