@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 void onAnalyzeSuccess(Bitmap mBitmap, String result) { Intent resultIntent = new Intent(); Bundle bundle = new Bundle(); bundle.putInt(CodeUtils.RESULT_TYPE, CodeUtils.RESULT_SUCCESS); bundle.putString(CodeUtils.RESULT_STRING, result); resultIntent.putExtras(bundle); CaptureActivity.this.setResult(RESULT_OK, resultIntent); CaptureActivity.this.finish(); }
Bundle args = new Bundle(); args.putInt("index", index); args.putString("type", TYPE_FRAGMENT); f.setArguments(args); View view = inflater.inflate(R.layout.template, container, false); if(getTypeFragment().equals(ArtistFragment.TYPE_FRAGMENT)){ view = null; view = inflater.inflate(R.layout.artist_details, container, false);
@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("myInt", myInt); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.my_layout, container); if (savedInstanceState != null) { myInt = savedInstanceState.getInt("myInt"); } ... return view; }
@Override public Message getDialogHandlerMessage() { Message msg = Message.obtain(); msg.what = DialogHandler.MSG_SHOW_SYNC_ERROR_DIALOG; Bundle b = new Bundle(); b.putInt("dialogType", getArguments().getInt("dialogType")); b.putString("dialogMessage", getArguments().getString("dialogMessage")); msg.setData(b); return msg; }
public class TestFragment extends Fragment { private static final String ATAG = "atag"; public static TestFragment getFragment(int value){ TestFragment fragment = new TestFragment(); Bundle bundle = new Bundle(); bundle.putInt(ATAG, 100); fragment.setArguments(bundle); return fragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.layout_fragment, container,false); Bundle b = getArguments(); if(b!= null) YOUR DATA = b.getInt(ATAG); return view; } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.first_tab_fragment, container, false); next = (Button)rootView.findViewById(R.id.nextbutton); next.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent("TAB_CLICKED"); Bundle bundle = new Bundle(); bundle.putInt(MainActivity.POSITION,1); intent.putExtras(bundle); getActivity().sendBroadcast(intent); } }); return rootView; }
arrayList.add("third"); Bundle innerBundle1 = new Bundle(); innerBundle1.putInt("inner", 1); Bundle innerBundle2 = new Bundle(); innerBundle2.putString("inner", "2"); innerBundle2.putStringArray("deep list", new String[] {"7", "8"}); Bundle b = new Bundle(); b.putBoolean("boolValue", true); b.putInt("intValue", 7); b.putLong("longValue", 5000000000l); b.putDouble("doubleValue", 3.14); b.putString("stringValue", "hello world"); b.putStringArray("stringArrayValue", new String[] {"first", "second"}); b.putStringArrayList("stringArrayListValue", arrayList); assertEquals(7, finalBundle.getInt("intValue")); assertEquals(5000000000l, finalBundle.getLong("longValue")); assertEquals(3.14, finalBundle.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals(1, finalInnerBundle.getInt("inner")); finalBundle = finalInnerBundle.getBundle("nested bundle"); assertEquals("2", finalBundle.getString("inner"));
Bundle toBundle() { Bundle bundle = new Bundle(); bundle.putString(KEY_POSITIVE_BUTTON, positiveButton); bundle.putString(KEY_NEGATIVE_BUTTON, negativeButton); bundle.putString(KEY_RATIONALE_MESSAGE, rationaleMsg); bundle.putInt(KEY_THEME, theme); bundle.putInt(KEY_REQUEST_CODE, requestCode); bundle.putStringArray(KEY_PERMISSIONS, permissions); return bundle; }
public class DetailsFragmentContainer extends Fragment { public static final String ARG_OBJECT = "details_fragment_container"; Bundle ids; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ids = getArguments(); View v = inflater.inflate(R.layout.fragments_container, container, false); return v; } public void createDetailsFragment(int parentItemId) { Fragment fragment = new DetailsFragment(); ids.putInt(Columns.COLUMN_PARENTITEMID, parentItemId); fragment.setArguments(ids); getChildFragmentManager().beginTransaction().add(R.id.fragments_frame, fragment).commit(); } }
@Override public Message getDialogHandlerMessage() { Message msg = Message.obtain(); msg.what = DialogHandler.MSG_SHOW_MEDIA_CHECK_COMPLETE_DIALOG; Bundle b = new Bundle(); b.putStringArrayList("nohave", getArguments().getStringArrayList("nohave")); b.putStringArrayList("unused", getArguments().getStringArrayList("unused")); b.putStringArrayList("invalid", getArguments().getStringArrayList("invalid")); b.putInt("dialogType", getArguments().getInt("dialogType")); msg.setData(b); return msg; } }
when(bundle.getChar(anyString(), anyChar())).thenAnswer(getOrDefault); doAnswer(put).when(bundle).putInt(anyString(), anyShort()); when(bundle.getShort(anyString())).thenAnswer(get); when(bundle.getShort(anyString(), anyShort())).thenAnswer(getOrDefault); when(bundle.getDouble(anyString(), anyDouble())).thenAnswer(getOrDefault); doAnswer(put).when(bundle).putString(anyString(), anyString()); when(bundle.getString(anyString())).thenAnswer(get); when(bundle.getString(anyString(), anyString())).thenAnswer(getOrDefault); when(bundle.getIntArray(anyString())).thenAnswer(get); doAnswer(put).when(bundle).putInt(anyString(), anyInt()); when(bundle.getInt(anyString())).thenAnswer(get); when(bundle.getInt(anyString(), anyInt())).thenAnswer(getOrDefault);
@Test public void getWrongType() { bundle.putFloat("foo", 5f); assertThat(bundle.getCharArray("foo")).isNull(); assertThat(bundle.getInt("foo")).isEqualTo(0); assertThat(bundle.getIntArray("foo")).isNull(); assertThat(bundle.getIntegerArrayList("foo")).isNull(); assertThat(bundle.getShort("foo")).isEqualTo((short) 0); assertThat(bundle.getShortArray("foo")).isNull(); assertThat(bundle.getBoolean("foo")).isFalse(); assertThat(bundle.getBooleanArray("foo")).isNull(); assertThat(bundle.getLong("foo")).isEqualTo(0); assertThat(bundle.getLongArray("foo")).isNull(); assertThat(bundle.getFloatArray("foo")).isNull(); assertThat(bundle.getDouble("foo")).isEqualTo(0.0); assertThat(bundle.getDoubleArray("foo")).isNull(); assertThat(bundle.getString("foo")).isNull(); assertThat(bundle.getStringArray("foo")).isNull(); assertThat(bundle.getStringArrayList("foo")).isNull(); assertThat(bundle.getBundle("foo")).isNull(); assertThat((Parcelable) bundle.getParcelable("foo")).isNull(); assertThat(bundle.getParcelableArray("foo")).isNull(); assertThat(bundle.getParcelableArrayList("foo")).isNull(); bundle.putInt("foo", 1); assertThat(bundle.getFloat("foo")).isEqualTo(0.0f); }