What is a “bundle” in an Android application

Bundles are generally used for passing data between various Android activities. It depends on you what type of values you want to pass, but bundles can hold all types of values and pass them to the new activity. You can use it like this: Intent intent = new… Intent(getApplicationContext(), SecondActivity.class); intent.putExtra(“myKey”, AnyValue); startActivity(intent); You can … Read more

Benefit of using Parcelable instead of serializing object

From “Pro Android 2” NOTE: Seeing Parcelable might have triggered the question, why is Android not using the built-in Java serialization mechanism? It turns out that the Android team came to the conclusion that the serialization in Java is far too slow to satisfy Android’s interprocess-communication requirements. So the team built the Parcelable solution. The … Read more

How to pass ArrayList from one activity to another? [duplicate]

You can pass an ArrayList<E> the same way, if the E type is Serializable. You would call the putExtra (String name, Serializable value) of Intent to store, and getSerializableExtra (String name) for retrieval. Example: ArrayList<String> myList = new ArrayList<String>(); intent.putExtra(“mylist”, myList); In the other Activity: ArrayList<String> myList = (ArrayList<String>) getIntent().getSerializableExtra(“mylist”);

Passing a Bundle on startActivity()?

You have a few options: 1) Use the Bundle from the Intent: Intent mIntent = new Intent(this, Example.class); Bundle extras = mIntent.getExtras(); extras.putString(key, value); 2) Create a new Bundle Intent mIntent = new Intent(this, Example.class); Bundle mBundle = new Bundle(); mBundle.putString(key, value); mIntent.putExtras(mBundle); 3) Use the putExtra() shortcut method of the Intent Intent mIntent = … Read more