Passing a Bundle on startActivity()?

后端 未结 6 1348
攒了一身酷
攒了一身酷 2020-11-22 03:28

What\'s the correct way to pass a bundle to the activity that is being launched from the current one? Shared properties?

6条回答
  •  一整个雨季
    2020-11-22 04:10

    you can use this code in your first activity :

     Intent i = new Intent(Context, your second activity.class);
            i.putExtra("key_value", "your object");
            startActivity(i);
    

    and get object in second activity :

     Intent in = getIntent();
        Bundle content = in.getExtras();
       // check null
            if (content != null) {
                String content = content_search.getString("key_value"); 
        }
    

提交回复
热议问题