[英]How to use 'bundle' instead of 'intent.putExtra()' in Fragment in Android
In Activity
I have used the following code for passing the value to other Activity classes: 在
Activity
我使用以下代码将值传递给其他Activity类:
intent.putExtra("book_arr", book_arr); // [putExtra(String *name*,Serializable *Value*)]
How to use like this code in Android Fragments? 如何在Android Fragments中使用此代码?
I have tried the following code, but it is not supporting serialized value: 我尝试了以下代码,但它不支持序列化值:
Bundle args =new Bundle();
args.putInt("book_arr", book_arr);
Thanks, 谢谢,
args.putSerializable("book_arr", book_arr);
If your book_arr
(which should be bookArr
) is a large array of heavy objects, consider making them Parcelable . 如果您
book_arr
(这应该是bookArr
)是一个大阵重物,可以考虑让他们Parcelable 。 You'll need to write additional code, but it's about x10 faster. 你需要编写额外的代码,但速度快了x10。 (if it's not a big object you probably shouldn't bother).
(如果它不是一个大对象你可能不应该打扰)。 This page can be helpful
此页面可能会有所帮助
http://www.developerphil.com/parcelable-vs-serializable/ http://www.developerphil.com/parcelable-vs-serializable/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.