ITeye博客

Bundle传递对象后,内存中该对象地址的问题

jogickis · 2013-12-17 09:54 · Android · 移动开发 · Markdown

在Fragment中传递 对象时发现了一个问题:将Appcation中全局对象传递一次后,发现该对象一直为null,这让我很郁闷

Bundle bundle = new Bundle();

bundle.putSerializable("custom", MyApplication.getInstance().getCustom());

mFragmentPersonal.setArguments(bundle);

custom = (Custom)getArguments()

.getSerializable("custom");

然后再通过MyApplication.getInstance().getCustom()的对象一直为null

没看源代码,以后探索,我觉得是Bundle在传递对象后,只能通过Key的方式获取,该对象以前的内存地址内容清空了。

 

然后我在考虑 是不是只是清空了该内存地址的一个引用,于是使用

 

 

Custom cus =  MyApplication.getInstance().getCustom();
bundle.putSerializable("custom", cus);

 

结果还是为null,说明不是清空一个引用

 

确认的之前和之后的Application是同一个对象

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。