简体   繁体   中英

What are differences between Bundle and JSONObject in Android development?

We can use JSONObject or JSONArray data structures for to store key-value pairs in the apps.

Also we can use Bundle for to store key-value pairs in the apps.

So, what are differences between their?

Is there any advantage/disadvantage of using any one instead of the other one?

In android, Bundle is associated with fragment/activity/Service/BroadcastReceiver. It is used to send data from one activity/fragment to another. we can send data through JSONObject too but we need medium to transfer data either common filesystem or local db or bundle. Bundle is a key value pair data structure as well as a medium. JSONObject is mostly used in web apis and to serialize Objects.

The are used in different cases. Bundle is used to transfer data between Activities, while JSONObject is used to contain JSON data and manipulate that same data. You can not pass directly a JSONObject to Activity, thus you need to us a Bundle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM