Examples of Intent and Bundles

Total Post:46


 1311  View(s)
Rate this:
I need a simple example code that will show me the difference between Intents and Bundles 
  1. Re: Examples of Intent and Bundles

    In MainActivity :
    Intent intent = new Intent(this, OtherActivity.class);
    intent.putExtra(OtherActivity.KEY_EXTRA, yourDataObject);

    In OtherActivity :
    public static final String KEY_EXTRA = "com.example.yourapp.KEY_BOOK";
    protected void onCreate(Bundle savedInstanceState) {
      String yourDataObject = null;
      Bundle extras = getIntent().getExtras();
      if (extras != null) {
          yourDataObject = extras.getString(KEY_EXTRA);
      if (yourDataObject != null) {
            // do stuff
      } else {
          throw new IllegalArgumentException("Activity cannot find  extras " + KEY_EXTRA);

      Modified On Apr-11-2018 12:29:14 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.