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

getArguments().getString always returns null in my Fragment

I have a following problem. I would like to save the values of some TextViews so that they can be retrieved and displayed after reutrning back to this Fragment (I use replace() method to switch Fragments). I followed the advice from this POST, so my…
fragon
  • 3,391
  • 10
  • 39
  • 76
1
vote
1 answer

How to prevent Meteor from installing own .android

Meteor installs its own bundle of Android devices in ~/.meteor/android_bundle/.android. But actually there is already a copy of that in ~/.android. Since it takes more than 1GB of space, does it make sense to have two different copies and if not,…
user3819370
  • 513
  • 1
  • 6
  • 15
1
vote
1 answer

Saving information from one fragment and dialog if the user navigates to another fragment

I have a screen where the user presses a button to bring up a DialogFragment with an EditText. They enter their information, and press Ok. If they press the button again, I've made it so the EditText will display the information they had just put…
pez
  • 3,859
  • 12
  • 40
  • 72
1
vote
4 answers

How to send ArrayList from one fragment to another in android

I want to pass ArrayList of NameValuePair from one fragment to another, here is my code param = new ArrayList(); param.add(new BasicNameValuePair("member_id",mem_id)); param.add(new…
1
vote
2 answers

Transferring data from 1 fragment to another fragment

Currently trying to use a bundle to transfer information from both my IncomeFragment and ExpenseFragment to HomeFragment but I'm unsure as to how to do it. I've tried implementing doubleA's code which he provided. This is my onAcceptClicked method…
Mark O'Sullivan
  • 10,138
  • 6
  • 39
  • 60
1
vote
4 answers

How does Bundle works?

I'm not asking how do I use it nor what does it do, how does it works. The question came to me when I though why didn't they just put a putExtra(String,Object) so I can pass an object. Obviously they just didn't forgot to do it, rather than the way…
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
1
vote
1 answer

Can't use get arguments to get bundle's data

when I run the app it crashes even though the code seems "legit" and there are no syntax errors. I have built two classes: In the first class, I will only preview the calling two the other class which made the app crashes. HelpFragment.java private…
jack
  • 195
  • 1
  • 2
  • 11
0
votes
0 answers

Android Browser close current tab

i am a react native dev so dont know about native code i want to close the current tab and open new tab with custom website and it should work for any browser out there how can i do that public void performRedirect(String browserPackage) {…
0
votes
2 answers

android.os.TransactionTooLargeException while transfering data via Bundle

Is there any workaround how to transfer larger amount of JSON files into another Activity? I'm getting android.os.TransactionTooLargeException: data parcel size 640176 bytes Activity is taking payload of certain array of JSONObjects which has to be…
martin1337
  • 2,384
  • 6
  • 38
  • 85
0
votes
0 answers

GlideException: Failed to load resource // java.io.FileNotFoundException(/di.GlideRequest@e41163b4: open failed: ENOENT (No such file or directory))

I have gallery project. I have a recycler view with rest api: ImageView, and 2 Text Views. I want to click small ImageView (this image is from rest api and it's downloaded from Glide) and Open This Image In another fragment with Glide using(Also…
0
votes
1 answer

How to check minsdkversion of generated appbundle?

i have build appbundle with minsdkversion 21. i give the file to devops for deployment, but he wants to make sure that the appbundle has minsdkversion set to 21. how do i check that? i heard bundletool but how do i use this to check value of…
nashihu
  • 750
  • 7
  • 17
0
votes
2 answers

How to get packageName in companion object?

I want to make a unique key when i send a intent/bundle to new Activity/Fragment in Android. So, i decided to use packageName. companion object { val MY_UNIQUE_KEY = "${this@Companion::class.java.packageName}MY_KEY" fun newInstance(user:…
0
votes
0 answers

Why is bundle received from Firebase Clound Messaging notification empty?

With many of our customers, especially on Xiaomi and Huawei devices, we see an 'empty' Bundle after the FCM notification is tapped by the user. The problem is not reproducible for us. We have a straight-forward implementation of FCM in our Android…
0
votes
0 answers

getArguments return null when passing bundle between fragments

I have 2 fragments called New_FieldFragment and MapFragment am trying to data using bundle via a function send results from New_FieldFragment to Fragment MapFragment when a submit button is clicked. However when I see if the bundle in MapFragment…
K-Genma
  • 21
  • 3
0
votes
0 answers

(Android) Your android app bundle is signed with the wrong key

Does anywone can solve this problem? As you see.. I did not miss (.jks) or private_key, either.. The correct error msg is: Your android app bundle is signed with the wrong key. It could be better to attach related photos, but stak says "You don't…
Code_Otaku
  • 21
  • 2