Reputation: 53
Using a recycler view. On selecting an card I have put an intent on click of card in recyclerviews adapter which changes the activity by these lines of code
Intent i =new Intent (view.getContext(),ExpandedActivity.class);
i.putExtra(passdate,members.getDate());
view.getContext().startActivity(i);
members.getDate(); is having values as I can see by Toast
I want to pass a string to another activity but I am getting null in other activity. here is the code in another activity.
Bundle extras;
extras = getIntent().getExtras();
date = extras.getString("passdate");
Making Toast of date shows null
Upvotes: 1
Views: 10614
Reputation: 3339
when we pass the data from onaActivity to AnotherActivity so Use KEY in Double Quote
Intent i =new Intent (view.getContext(),ExpandedActivity.class);
i.putExtra("passdate1",members.getDate1());
i.putExtra("passdate2",members.getDate2());
view.getContext().startActivity(i);
String date1 = getIntent().getExtra().getString("passdate1");
String date2 = getIntent().getExtra().getString("passdate2");
Upvotes: 1
Reputation: 20513
When putting values inside intent/bundle you have to provide a key under which you will store the value
Setting the values
Intent i = new Intent (view.getContext(), ExpandedActivity.class);
i.putExtra("KEY", members.getDate());
view.getContext().startActivity(i);
Getting the values
Bundle extras;
extras = getIntent().getExtras();
date = extras.getString("KEY");
Upvotes: 2
Reputation: 5134
You have to set KEY into double quote like below code:
Intent i =new Intent (view.getContext(),ExpandedActivity.class);
i.putExtra("passdate",members.getDate());
view.getContext().startActivity(i);
and for getting Intent data use below code:
String date = getIntent().getExtra().getString("passdate");
Upvotes: 0