This question may sound stupid but I wana know When do we put activity name in Intent.putExtra()
? In one case we are putting extra only with bundle and in other case we are passing it with class name. I am a little confused should we use Intent.putExtra(String, Bundle)
we already have passed the activity name in Intent
constructor or not?
Thanks for your help!
I think you mean
putExtra(String, Bundle)
vsputExtras(Bundle)
(with s).The first adds the bundle as the value for the key you provide. The bundle is simple an object value.
The second adds all the key/value pairs from the provided bundle to the intent. In this case the content of the bundle will be added to the intent, not the bundle itself.
Think of them as in
Map
interface:vs
Look at source code http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.4_r1.2/android/content/Intent.java#Intent.putExtras%28android.os.Bundle%29
The approach is just the difference here. If you use a
Bundle
you can store almost all types in it:and pass it to an activity
and in the other activity which recieves the info, just grab the content of the bundle like this:
and grab each element in the
bundle
like this: