@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. }
public class SecondFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.second_frag, container, false); TextView tv = (TextView) v.findViewById(R.id.tvFragSecond); tv.setText(getArguments().getString("msg")); return v; } public static SecondFragment newInstance(String text) { SecondFragment f = new SecondFragment(); Bundle b = new Bundle(); b.putString("msg", text); f.setArguments(b); return f; } }
private Bundle getAuthToken(Account account, String authTokenType) throws OperationCanceledException, IOException, AuthenticatorException { Bundle result = new Bundle(); String authToken = blockingGetAuthToken(account, authTokenType, false); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); result.putString(AccountManager.KEY_AUTHTOKEN, authToken); if (authToken != null) { return result; } if (!authenticators.containsKey(account.type)) { throw new AuthenticatorException("No authenticator specified for " + account.type); } Intent resultIntent = new Intent(); result.putParcelable(AccountManager.KEY_INTENT, resultIntent); return result; }
/** * Create bundle with standard arguments * * @param title * @param message * @param requestCode * @return bundle */ protected static Bundle createArguments(final String title, final String message, final int requestCode) { Bundle arguments = new Bundle(); arguments.putInt(ARG_REQUEST_CODE, requestCode); arguments.putString(ARG_TITLE, title); arguments.putString(ARG_MESSAGE, message); return arguments; }
@Override public void onResult(Bundle result) throws RemoteException { if (result != null) { String label = result.getString(AccountManager.KEY_AUTH_TOKEN_LABEL); Bundle bundle = new Bundle(); bundle.putString(AccountManager.KEY_AUTH_TOKEN_LABEL, label); super.onResult(bundle); } else { super.onResult(null); } } }.bind();
/* Start Activity */ public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName("com.thinoo.ActivityTest", "com.thinoo.ActivityTest.NewActivity"); startActivityForResult(intent,90); } /* Called when the second activity's finished */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch(requestCode) { case 90: if (resultCode == RESULT_OK) { Bundle res = data.getExtras(); String result = res.getString("param_result"); Log.d("FIRST", "result:"+result); } break; } } private void finishWithResult() { Bundle conData = new Bundle(); conData.putString("param_result", "Thanks Thanks"); Intent intent = new Intent(); intent.putExtras(conData); setResult(RESULT_OK, intent); finish(); }
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_layout, container, false); mTime = savedInstanceState.getString("time_key"); } else { mTime = "" + Calendar.getInstance().getTimeInMillis(); public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString("time_key", mTime);
@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; }
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(5000000000l, json.getLong("longValue")); assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals("hello world", json.getString("stringValue")); assertEquals(1, innerJson.getInt("inner")); innerJson = innerJson.getJSONObject("nested bundle"); assertEquals("2", innerJson.getString("inner"));
@Override public void onSaveInstanceState(Bundle outState) { outState.putString("message", "This is my message to be reloaded"); super.onSaveInstanceState(outState); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { String message = savedInstanceState.getString("message"); Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } }
/** * Logs an app event that tracks that the application was open via Push Notification. * @param payload Notification payload received. */ public void logPushNotificationOpen(Bundle payload, String action) { String campaignId = null; try { String payloadString = payload.getString(PUSH_PAYLOAD_KEY); if (Utility.isNullOrEmpty(payloadString)) { return; // Ignore the payload if no fb push payload is present. } JSONObject facebookPayload = new JSONObject(payloadString); campaignId = facebookPayload.getString(PUSH_PAYLOAD_CAMPAIGN_KEY); } catch (JSONException je) { // ignore } if (campaignId == null) { Logger.log(LoggingBehavior.DEVELOPER_ERRORS, TAG, "Malformed payload specified for logging a push notification open."); return; } Bundle parameters = new Bundle(); parameters.putString(APP_EVENT_PUSH_PARAMETER_CAMPAIGN, campaignId); if (action != null) { parameters.putString(APP_EVENT_PUSH_PARAMETER_ACTION, action); } logEvent(APP_EVENT_NAME_PUSH_OPENED, parameters); }
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; }
Bundle bridgeArguments = new Bundle(); bridgeArguments.putString(BRIDGE_ARG_ACTION_ID_STRING, callId); Utility.putNonEmptyString(bridgeArguments, BRIDGE_ARG_APP_NAME_STRING, applicationName); Bundle methodArguments = (params == null) ? new Bundle() : params; intent.putExtra(EXTRA_PROTOCOL_METHOD_ARGS, methodArguments); } else { intent.putExtra(EXTRA_APPLICATION_NAME, applicationName); intent.putExtras(params);
public class ThirdFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.third_frag, container, false); TextView tv = (TextView) v.findViewById(R.id.tvFragThird); tv.setText(getArguments().getString("msg")); return v; } public static ThirdFragment newInstance(String text) { ThirdFragment f = new ThirdFragment(); Bundle b = new Bundle(); b.putString("msg", text); f.setArguments(b); return f; } }
public static Intent getPreferenceSubscreenIntent(Context context, String subscreen) { Intent i = new Intent(context, Preferences.class); i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, "com.ichi2.anki.Preferences$SettingsFragment"); Bundle extras = new Bundle(); extras.putString("subscreen", subscreen); i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, extras); i.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true); return i; }