

Retrieve the data back in the launched Fragment in the onCreateView method. String value = getIntent().getExtras().getString('my_key') Ĭreate a bunlde and put your key and value to it, then set the argument of the framgent with this bundle. To retrieve the data from the launched activity in the onCreate method. Passing data to activity using a new Bundle. Passing data to activity using the Bundle from the Intent. Intent intent = new Intent(this, MyActivity.class) Passing data to activity using the putExtra() directly on the intent. In the following examples, the primitve type string is used for demonstration purpose. Here I want to make a RecyclerView consist of CardView, which is inside a Fragment. Step 2 Add the following code to res/layout/activitymain.xml. Bundle has put and get methods for all primitive types, Parcelables, and Serializables. This example demonstrate about Fragment Tutorial with Example in Android Studio Step 1 Create a new project in Android Studio, go to File New Project and fill all required details to create a new project.

When passing data to an activity or a fragment in Android, the Bundle is used to contain the data and ship it to the activity or fragment to be launched.
