Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Date extra from an intent?

I am packing an intent and one of the Extras I add is a date object, like this:

intent.putExtra(DATE_EXTRA, t.getDate());

Later, when I reading the extras, I try to get the Date like this:

this.date = new Date(intent.getExtras().getString(DATE_EXTRA));

However, this returns an error about the String being empty. I don't think the above is the right way to do it, because I am not looking for a string, but I have not been able to find an intent.getDateExtra() method anywhere. What do I do?

I know that the date was passed properly, because I can see it while debugging: enter image description here

like image 513
AdamMc331 Avatar asked Oct 31 '25 10:10

AdamMc331


1 Answers

Replace:

this.date = new Date(intent.getExtras().getString(DATE_EXTRA));

with:

this.date = (Date)intent.getSerializableExtra(DATE_EXTRA);

and see if that helps.

like image 118
CommonsWare Avatar answered Nov 03 '25 01:11

CommonsWare