androidandroid-activityextras

Getting extras always null


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


Solution

  • 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");