Android:在putExtra中传递日期 [英] Android: Passing Date in putExtra

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

问题描述

我正在启动一个活动,并希望向其传递一个Date(Time)值.我已经用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);

但是我如何在ActivityonCreate()中检索它;我看不到extras.getDate()吗?

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

我应该将其转换为Float然后再返回(在Activity中)吗?

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?

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

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