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
2
votes
1 answer

GitHub Actions Error on r0adkll/sign-android-release@v1 -> no such file or directory, scandir 'app/build/outputs/bundle/release'

I am getting this error: Run r0adkll/sign-android-release@v1 Preparing to sign key @ app/build/outputs/bundle/release with signing key Error: ENOENT: no such file or directory, scandir 'app/build/outputs/bundle/release' I see in other posts that…
2
votes
0 answers

Google Play Asset Delivery: 2GB size limit for all packets or just for download?

Google states a 2GB Download size limit for the Android App Bundle when using Play Asset Delivery. Does that include all "on-demand" asset packs? E.g. I have an app with on-demand packs for different languages. Can I only upload a total of 2GB to…
2
votes
1 answer

Android: test conditional feature delivery based on country

I will use a dynamic feature in an android app. This feature should be available in a specific country. So I use the country condition for the dynamic feature module: My code:
2
votes
2 answers

Plugin "Android Bundle Support" is incompatible

everyone, I have a very weird error when i launch android studio since last update. I have this error: Plugin Error: Plugin "Android Bundle Support" is incompatible (until build AI-195.SNAPSHOT < AI-201.8743.12). I can't find any info online about…
2
votes
1 answer

Android On Demand delivery data binding

I'm trying to create a project with on demand delivery. I created a simple project with one activity which contains a button that will open another application which is added as a module. I followed the instruction from documentation. But when I try…
ovluca
  • 291
  • 1
  • 15
2
votes
1 answer

Instance state not restoring/saving correctly

I'm attempting to save and restore a boolean field when the screen orientation changes. For whatever reason the field is saving/restoring correctly during the first orientation change, but when the orientation changes back to the initial state, the…
Alex
  • 139
  • 9
2
votes
2 answers

Android Bundle ArrayOutOfBoundException when getting data

I'm using a bundle to pass data between thread. Sometime when i try to read the data's bundle i got an ArrayIndexOutOfBoundsException : java.lang.ArrayIndexOutOfBoundsException: length=0; index=4 at…
grunk
  • 14,718
  • 15
  • 67
  • 108
2
votes
1 answer

Android Auto: paginating a MediaBrowserService by passing extras options bundles fails

Recently, I've been trying to implement pagination on the Android Auto part of my application. To do so, I took inspiration from this Medium post. This question is also related. However, I am still stuck: while I can make the code from the Medium…
2
votes
4 answers

Intent.putExtra (key,value) is not working

I got a ValueEventListener query.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { final Intent intent = new Intent(BackgroundService.this,…
2
votes
1 answer

How to get extras without a key?

As is known to all, we can put the extra info into an Intent by using putExtra/putExtras, and pass it to another app. At the destination, we can use getxxxExtra/getExtras to get this information. However, all these methods request a key. I was…
ignorer
  • 327
  • 1
  • 11
2
votes
1 answer

Fragment's bundle is null in onCreate despite overriding onSaveInstanceState

My MainActivity uses Fragments, a simplified version of the layout looks like this:
2
votes
1 answer

send data from IntentService to Fragment

As i tried BroadCastReciever in this question, I'v tried pass data with arguments too in my Log it's ok . Bundle bundle = new Bundle(); ArticleDetailFragment fragobj = new…
user7697994
2
votes
1 answer

Why Bundle in Intent get lost?

I have a Serializable SpecialObject with some parameters (Location etc. in turn Serializable as well) I would like to open a Fragment (MySpecialFragment) by an Activity (MySpecialActivity) by handling over a SpecialObject object. It works so far, I…
Murat Ceven
  • 264
  • 1
  • 6
2
votes
0 answers

Android Studio: Passing longitude and latitude

My application is a weather api to gather information about weather of the current location. I do this by putting in a postcode and then the ASync gathers the information. I am also using GooglePlayServices to find the location i send to the device…
2
votes
1 answer

Passing Data From Activity to another and then passing to fragment in ViewPager

I'm trying to pass data from my MainActivty to another one with ViewPager, and get that data in the Fragment. I tried so may ways but the app crashed every time. here is my Classes: My Holder: @Override public void onBindViewHolder(main_rv_holder…