Questions tagged [android-bundle]

A mapping used to pass data between various Activities & Fragments in Android

A Bundle is a mapping from String values to various Parcelable types.

It is used in Android to store and retrieve datas inside an Activity when the orientation changed or to pass these values between two Activities. You can also used a Bundle to pass data between Activity and Fragments.

Its initialization is as follows:

Bundle b = new Bundle();  
// Put values (ex: a String):  
b.putString("value_name",value);  

Then, it is related to an Intent and pass to a new Activity with this Intent:

Intent intent = new Intent(ActivityA.this,ActivityB.class);
intent.putExtras(b);
startActivity(intent) // launch ActivityB and pass the Bundle to it  

This map allows multiples types and retrieve its values inside the new Activity as follows:

Bundle extras = getIntent().getExtras(); 
String received_value = extras.getString("value_name");

When the device does a rotation, the Activity is destroyed and recreated. The datas can be stored to avoid to lost some informations:

By default, the system uses the Bundle instance state to save information about each View object in your activity layout (such as the text value entered into an EditText object).`

In similar fashion you can use bundles to pass data between fragment :-

Fragment fragment = new Fragment();
Bundle bundle = new Bundle();
bundle.putInt(key, value);
fragment.setArguments(bundle);

Bundle has put methods for lots of data types.

Then in your Fragment, retrieve the data (e.g. in onCreate() method) with:

Bundle bundle = this.getArguments();
int myInt = bundle.getInt(key, defaultValue);

See the SO question What is a "bundle" in an Android application
Also the Recreating an Activity topic from Google Documentation For more information, read the reference in Documentation: Bundle
Related tags: , , ,

302 questions
1
vote
1 answer

java - error: cannot find symbol . in generated classes SomeDirections.SomeAction

I am implementing navigation between Fragments from different flows (single-activity architecture with flow fragments) meaning from one nested graph to another. I am trying to pass one testID argument using Safe Args. In my origins Fragment I use…
1
vote
3 answers

Passing variables from Parent to Child views in Android

Whats the difference between pass the variables like this: Intent intent = new Intent(mCtx, DetailsActivity.class); intent.putExtra("pId", id); intent.putExtra("pType", type); mCtx.startActivity(intent); and using the keyword Bundle? Intent intent…
Learn2Code
  • 1,974
  • 5
  • 24
  • 46
1
vote
2 answers

android bundle size much bigger than in universal apk

When I built universal apk it size was 170mb. After I implemented extension files (due to the large asset folder) I have to build bundles. But the bundle size is much bigger - 283mb. Uppon unzipping aab file I see, that just lib folder weights …
Yarh
  • 4,459
  • 5
  • 45
  • 95
1
vote
1 answer

Passing a parcelable bundle backwards using the OnBackPressedCallback

In my app I am using the OnBackPressedCallback and calling the findNavController.popBackStack to manage backwards navigation. One limitation I have encountered is that I cannot find a way to pass a parcelable bundle back when the user clicks the…
1
vote
2 answers

Keep special chars when using deep link with query params with Navigation Jetpack

I am sending a raw JSON as a String in URI navigation with Navigation library. It looks like this. findNavController().navigate( Uri.parse("android-app://androidx.navigation/checkout/${Gson().toJson(orderSummary)}"), …
Rainmaker
  • 10,294
  • 9
  • 54
  • 89
1
vote
1 answer

Modules 'base' and 'AdharVerificationDynamicFeature' contain entry 'assets/crashlytics-build.properties' with different content

I am generating Signed Build Bundle. Instant App Module is launching perfectly in device but when I am generating Signed Build Bundle I got this error. 'Modules 'base' and 'AdharVerificationDynamicFeature' contain entry…
Prakash
  • 149
  • 7
1
vote
3 answers

I have issues passing data from my parent activity to a child fragment on a BottomViewNavigation

guys please I'm working on an android project and I need to pass data from a parent activity that is hosting a BottomNavigationView to its child fragment. I've tried to follow some solutions online but seems my issues is peculiar because it involves…
Uncle Sam
  • 61
  • 2
  • 10
1
vote
1 answer

DialogFragment Bundle putSerializable: Sometimes giving NotSerializableException

I have a object, that has other objects inside. I need to pass that object to a FragmentDialog, so I made that object Serializable and it's working perfectly in my device. public static SelectTeamDialog newInstance(Data data) { SelectTeamDialog…
1
vote
0 answers

How to put and get a list of strings to Bundle in Kotlin

Assume there is list of strings like val list = listOf("a", "b") How do I save it into and get from Bundle in Kotlin? I've tried saving like this but it gives the type mismatch error outState.putStringArrayList(KEY, list.toTypedArray()) Type…
yaugenka
  • 2,602
  • 2
  • 22
  • 41
1
vote
1 answer

Activity bundle missing extras even though they should always be added in the newIntance method

I have an unexpected crash on my app in production. I have an activity that I always start using a newInstance method that add some extras to the intent : public static Intent newInstance(final Context context, @NonNull final Location location) { …
1
vote
0 answers

How to open android bundle file?

How can I unpack/pack .bundle files from the installed games/application in android? I have unpacked an apk and there are .bundle file types in its asset. I would like to unpack the .bundle files and see what is inside. I tried google and did not…
hunerkiel
  • 11
  • 3
1
vote
2 answers

How to send ArrayList() through activities

I have this class: public class FlightData implements Parcelable { private double x; private double y; private double time; FlightData(double x, double y, double time){ this.x = x; this.y = y; this.time =…
user6142080
1
vote
2 answers

Pass data between Activity and Fragment

I want to pass data from Activity to Fragment using Bundle (I used Bundle to passing data between 2 Fragment, and that's worked). In my Activity I have a ListView, in the OnItemClickListener I want to open a new Fragment, and the Item, which…
Cam
  • 61
  • 6
1
vote
3 answers

Return list from a Activity to Main Activity?

I want MainActivity call a SecondActivity and the SecondActivity return a List of Strings. Every answer that I have read explains how to pass data from MainActivity to SecondActivity. I have created an Activity that calculate all possible IPs in…
0sunday
  • 15
  • 7
1
vote
2 answers