Search code examples
androidandroid-activity

Android: Passing Date in putExtra


I'm launching an activity and would like to pass a Date(Time) value to it. I've passed all my other parameters with i.putExtra("noteName", "Hello World") but I'm clueless on how to pass the date value and then retrieve it as a date with getExtra().

I can easily use i.putExtra("noteDate",noteDate);

but then how do i retrieve it in the Activity's onCreate(); I don't see an extras.getDate() ?

Should I convert it to Float and then back (in the Activity)?

Thanks


Solution

  • I've simply used

    i.putExtra("noteDate",myDate);
    

    and then on the activity I used:

    Date dt = new Date(extras.getString("noteDate"));
    

    and it works like a charm!? Is this dangerous? To assume the date will always be parsed correctly on all devices?