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
6
votes
2 answers

what is the integer that return by getInt(string key) in android.os.Bundle?

i read document about getInt() method : public int getInt (String key) Returns the value associated with the given key, or 0 if no mapping of the desired type exists for the given key. Parameters: key a string return: an int value but i can't…
hamid_c
  • 849
  • 3
  • 11
  • 29
5
votes
2 answers

Google Play - Internal Testing - Inactive

One of the developers by mistake published the app on Google Play before release. Then it was unpublished for safety reasons. Then internal testing release was created, countries selected, testers added... (with .oob bundle). Everyone got invites,…
5
votes
1 answer

Android runtime permissions process: Can I send extras with ActivityCompat.requestPermissions?

Are there any methods to send bundle/extras (like what we do with intents) during a request for granting dangerous permissions of android? In normal process for granting dangerous permissions for android, we should call…
5
votes
3 answers

Fragment in viewpager savedinstancestate is always null

I know this question has been asked before but none of the answers given so far is of any help to me. I have a viewpager which is populated with fragments (android.support.v4.app.Fragment) from a FragmentStatePagerAdapter . Some of these fragments…
5
votes
5 answers

Android pass persistent information in bundles or use singleton pattern?

Just wondering what is a better practice to pass information between activites, adding it to a bundle or using a singleton class to store and access this data. I have used both in the past for various android side projects, but I am now working on…
4
votes
1 answer

Does the data (Bundle) from navArgs persist after the killing and recreation of the Activity (and Fragment) by the system?

This question has been answered already by Ian Lake, from Google. I was suggested to recreate the question on StackOverflow and answer it myself, so it might help someone else who googles it :) When using Navigation API, and SafeArgs: val args:…
4
votes
5 answers

After Build Bundle, There is no aab file in release folder

The only file in release is the build apk. The aab file is only in debug folder eventhough already choose release when want to generate sign bundle.
Kucing Kiki
  • 113
  • 1
  • 10
4
votes
1 answer

java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 558780 bytes when navigating between fragment

I am using Bundle to transfer data between activities and fragments. When I navigate from one fragment to new fragment, Without transferring data or using Bundle to get the data, Application is crashing with below error. > > 10-09 11:36:09.100…
Rakesh
  • 14,997
  • 13
  • 42
  • 62
4
votes
1 answer

Program type already present: android.support.v7.appcompat.R

I'm facing issue while try to make bundle with following gradle and dependencies project gradle: buildscript { ext.kotlin_version = '1.2.51' repositories { jcenter() maven { url 'https://maven.google.com/' …
4
votes
2 answers

Building App Bundle Proguard Error

When i try to build app bundle with android studio 3.2 canary 17 i get the following error message. i have no idea what is missing angular bracket went through all of my proguard files and everything seems fine and is working in older version of…
4
votes
1 answer

How convert Bundle to WorkManager Data

I try to get rid of IntentService when handle GCM as described here. Because of Android O background limitation. But i can't pass Bundle extras with push info as parameter to WorkManager from BroadcastReceiver. Is there any way to put Bundle into…
4
votes
2 answers

How to examine the size of the Bundle object in onSaveInstanceState?

I am using Android Studio 3.0.1 which allows to inspect the Bundle object in onSaveInstanceState: @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } To do so add a breakpoint and once the…
JJD
  • 50,076
  • 60
  • 203
  • 339
4
votes
1 answer

Cases when savedInstanceState is NOT null

If I do not explicitly call onSaveInstanceState(), which are possibilities, when savedInstanceState is not null in onCreate? I see one option, when system recreates my app after crash - then savedInstanceState is not null. Which are other options?
4
votes
3 answers

Cannot launch AVD in emulator. ?android studio

my emulator is not runnnig and gives the error in image below error image and test at run window C:\Users\Wahlah\AppData\Local\Android\sdk\tools\emulator.exe -netdelay gprs -netspeed full -avd Nexus_4_API_21 This application has…
AIR TRAVELS
  • 75
  • 2
  • 9
4
votes
3 answers

Can't receive Intent.extras() from Camera after making a photo

I found it's a common problem with capturing photo and receiving full size photo instead of thumbnail (according to: http://developer.android.com/training/camera/photobasics.html ). Taking photo and receiving thumbnail is easy, but rest of tutorial…
jean d'arme
  • 4,033
  • 6
  • 35
  • 70
1 2
3
20 21