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: , , ,

282 questions
10
votes
3 answers

Store and retrieve array list in Bundle in Android

How do I store and retrieve an array list of values in a Bundle in Android? Any examples?
mohan
  • 11,969
  • 29
  • 102
  • 172
10
votes
2 answers

Put interface in bundle to start a new activity

I need to start an activity from 2 different screens that have two different models but, both models have some shared information which is the one that I need in the new activity. The problem is that I cannot make those models to extend from the…
FVod
  • 1,955
  • 3
  • 17
  • 41
9
votes
1 answer

React-native 0.61.2 with hermes disassembling index.android.bundle

I created a release build of my app with react-native 0.61.2 and enabled Hermes. In my Crashlytics I receive information about crashes along with stacktraces. Perviously I used to apply apktool to extract index.android.bundle from my apk, and it…
9
votes
4 answers

Send data to fragment with FragmentTransaction

I'm in my fragment class calling this: @OnClick(R.id.blockedLinkLayout) public void onBlockedClick(){ final FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.content, new SettingsBlockedUsersFragment(),…
y07k2
  • 1,668
  • 3
  • 15
  • 33
8
votes
3 answers

Send argument through PendingIntent of NavDeepLinkBuilder

I'm having some difficulties sending an argument through a PendingIntent of a notification using NavDeepLinkBuilder. I'm able to get the destination Activity to launch by clicking the notification, but the Activity's Intent doesn't contain the…
8
votes
3 answers

Mutation of a Bundle object

I'm working with the legacy code and I found an inconsistent behavior in this function: @Override public void openFragment(final Class fragmentClass, final boolean addToBackStack, …
Maxim G
  • 1,489
  • 1
  • 13
  • 23
8
votes
2 answers

Sending Intent from BroadcastReceiver class to currently running activity

I have a class which extends BroadcastReceiver. On receiving a SMS, I would like to pass information to my main activity class to display the text in a box (Append, if already text is present). public class SmsReceiver extends BroadcastReceiver…
user1692342
  • 4,096
  • 8
  • 47
  • 103
6
votes
2 answers

How to generate an APK (NOT APKS ) from AAB using bundletool?

I'm looking for a solution to generate an APK from Android App Bundle which will help me to share the App for internal testing rather publishing on Google Play Beta Testing. Is there a way or a command using bundletool?
6
votes
1 answer

Passing List of Objects to Fragment

class CholesterolPagingFragment: Fragment() { companion object { fun newInstance(): CholesterolPagingFragment { val args = Bundle() val fragment = CholesterolPagingFragment() fragment.arguments =…
kokilayaa
  • 427
  • 2
  • 6
  • 17
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
  • 808
  • 3
  • 11
  • 28
5
votes
2 answers

android release app bundle build missing native lib .so files

case I have an app when i work with it in debug mode everything is ok ! but when i try to build apk bundle for release and try to install app through play store the is missing the .so files i reverse- engineered the apk and couldn't find a single…
5
votes
0 answers

Android getIntent().getExtras() returning null sometimes

I was going through Crashlytics logs for my app and found that there is a NullPointerException on some devices because getIntent().getExtras() is returning null. This behavior is seen only on a few devices and I am not able to reproduce this bug. I…
prempal
  • 61
  • 5
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

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…
1
2
3
18 19