1

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

Aarje Ishu
  • 53
  • 2
  • 11

3 Answers3

2

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");
Marko
  • 20,385
  • 13
  • 48
  • 64
  • I have one more question how can I pass more than one values to the activity – Aarje Ishu Sep 22 '15 at 06:14
  • As you did with the first, just put multiple extras inside your intent. Again just call `i.putExtra("ANOTHER_KEY", value);` – Marko Sep 22 '15 at 06:16
1

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");
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28
0

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");
Sagar Zala
  • 4,854
  • 9
  • 34
  • 62