Why should I use Bundle if I can pass values to new Activity by putting it directly to Intent extras?
Bundle 是数据(键值对集合)。Intent 是 Android 很重要的一种机制,可以定义要执行的操作、要操作的数据(通过 Extras 携带数据,Bundle 是可以携带的数据类型之一)。Intent 的内涵要远比 Bundle 大的多。
这个问题主要是困惑于,既然 intent extras 和 Bundle 都可以携带数据,用哪一种有什么优势吗?
The code using an additional bundle is slightly easier to manage, being more general. If one day you decide that - before sending information inside an intent - you want to serialize the data to database - it will be a bit cleaner to have a bundle that you can serialize, all with one object.
Once data is put in a Bundle, you can send the same data through multiple intents.
you can isolate their creation/reading more easily, therefore separating the code handling the bundles from the code of the UI.