I want to pass a bundle on click of button to new activity. This is the code for bundle in the class adapter which extends recycleview adapter
private void passBundle (Vendor mItemSelected){
mBundle = new Bundle();
mBundle.putString("VENDOR_ID", mItemSelected.getVENDORID());
mBundle.putString("CAT_ID", "" + mItemSelected.getVEN_TYPE());
mBundle.putString("VENDOR_NAME", "" + mItemSelected.getVENDORNAME());
mBundle.putString("CAT_ID", "" + mItemSelected.getVEN_TYPE());
mBundle.putString("CAT_ID", "" + mItemSelected.getVEN_TYPE());
mBundle.putString("VENDOR_AREA", "" + mItemSelected.getVENDORADDRESS());
Intent in = new Intent(context,Chat_Activity.class);
in.putExtra("Bundle", mBundle);
Context.startActivity(in);
}
and this is the code where i retrieve the bundle data in another activity.
Bundle bundle = new Bundle();
chatVenID = bundle.getString("VENDOR_ID", "");
catID = bundle.getString("CAT_ID", "");
vendorName = bundle.getString("VENDOR_NAME", "");
vendorArea = bundle.getString("VENDOR_AREA","");
You can invoke
Bundle bundle = getIntent().getBundleExtra("Bundle");
chatVenID = bundle.getString("VENDOR_ID", "");
in onCreate(Bundle savedInstanceState) method; new Bunlde() will create a new bundle object, can't get pass value from prev activity.
Bundle bundle = new Bundle();
In this code, you are creating a new object of Bundle, so you wont' get any values. Change it to
getIntent().getBundleExtra("Bundle")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.