如何从意图获得额外的日期? [英] How to get Date extra from an intent?
本文介绍了如何从意图获得额外的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在打包意图,我添加的Extras之一是日期对象,如下所示:
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));
但是,这将返回有关String为空的错误.我不认为以上方法是正确的方法,因为我没有在寻找字符串,但是我无法在任何地方找到intent.getDateExtra()
方法.我该怎么办?
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:
推荐答案
替换:
this.date = new Date(intent.getExtras().getString(DATE_EXTRA));
具有:
this.date = (Date)intent.getSerializableExtra(DATE_EXTRA);
看看是否有帮助.
这篇关于如何从意图获得额外的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文