安卓:在putExra传递日期 [英] Android: Passing Date in putExra

查看:80
本文介绍了安卓:在putExra传递日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发起的活动,并希望传递一个日期(时间)的价值吧。我已经通过我的所有其他参数与 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?

这篇关于安卓:在putExra传递日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆