i don' know how to give setOndateChangeeListener date to another activity with intent object

Viewed 18

I really don'n know how to pass my calenderview data to another activity. I use setonDateChangeListener and i want to pass this date to another activity. please help me

eventButton.setOnClickListener(v -> {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            String selectyear = Integer.toString(calendar.get(Calendar.YEAR));
            String selectmonth = Integer.toString(calendar.get(Calendar.MONTH + 1));
            String selectday = Integer.toString(calendar.get(Calendar.DATE));

            Intent intent = new Intent(getApplicationContext(), EventActivity.class);
            intent.putExtra("year", selectyear);
            intent.putExtra("month", selectmonth);
            intent.putExtra("day", selectday);

            startActivity(intent);
        });
1 Answers

I think you're in the right path already. Assuming you're actually extracting the information you want, you should be able to grab the intent content from the EventActivity by calling:

public void onCreate(..) {
   super.onCreate(..)
   ...
   final Intent i = getIntent();
   if (i != null && i.extras != null) {
      final String year = i.extras.contains("year", defaultYearValue);
      final String month = i.extras.contains("month", defaultMonthValue);
      final String day = i.extras.contains("day", defaultDayValue);
      // Do something with the info
   }
   ...
}
Related