整数序列化传递捆绑问题 [英] Problems passing integer and serializable on bundle
本文介绍了整数序列化传递捆绑问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想传递一个序列化和整数或字符串,但在我的孩子的活动我只得到了序列化
I'm trying to pass a serializable and an Integer or a String but on my child activity I only get the serializable
父活动
Intent intent = new Intent(Class1.this, Class2.class);
Bundle bundle = new Bundle();
bundle.putInt("key", 23);
bundle.putSerializable(serializable, object);
intent.putExtras(bundle);
startActivityForResult(intent, 1);
子活动
Intent intent = getIntent();
int intKey;
Bundle bundle = intent.getExtras();
object = (Object) bundle.getSerializable(serializable);
intKey = bundle.getInt("key", 0);
我得到的序列化对象,但我不能让藏汉
I get the serializable object but I can't get the integer aswell
推荐答案
尝试,直接把INT的意图,而不是通过捆绑。
含义:
Try and put the int directly on Intent and not through bundle. Meaning :
intent.putExtra("key", 23);
和这件事吧:
intent.getIntExtra("key", 23);
应工作
但是,如果你有一个原因,你想用的包,则可以尝试什么Sajmon中的评论称,和 bundle.getInt(密钥)
我读的地方,这是不一样的,我不知道为什么。
But if you have a reason you wanna use the bundle you can try what Sajmon said in the comment, and bundle.getInt("key")
i read somewhere that it's not the same, i'm not sure why.
这篇关于整数序列化传递捆绑问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文