安卓:在putExra传递日期日期、putExra

由网友(三千痴妄)分享简介:我发起的活动,并希望传递一个日期(时间)的价值吧。我已经通过我的所有其他参数与 i.putExtra(noteName,Hello World的)但我无言以对如何传递日期值,然后检索它作为一个日期与 getExtra()。I'm launching an activity and would like to pass...

我发起的活动,并希望传递一个日期(时间)的价值吧。我已经通过我的所有其他参数与 i.putExtra(noteName,Hello World的)但我无言以对如何传递日期值,然后检索它作为一个日期与 getExtra()

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.putExtra(noteDate,noteDate);

但我如何检索它在活动的onCreate();我没有看到 extras.getDate()

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)?

感谢

推荐答案

我只是用

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?

阅读全文

相关推荐

最新文章