@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"); }
@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. }
@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); }
@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"); }
@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); }
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);
@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); }
@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); }
@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); }
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); } } } }
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); }
@Override public Parcelable onSaveInstanceState() { Bundle bundle = new Bundle(); bundle.putString("stringState", stringState); bundle.putParcelable("beanState", beanState); return bundle; }