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

How to receive Intent in Activity

Honestly I did somesearch about this before asking. how to receive intent from activity to fragmentactivity I am trying to use viewpager. I am having error here in get argumentsBundle extras = getArguments(); public class SingleViewActivity extends…
Moudiz
  • 6,775
  • 18
  • 67
  • 139
4
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…
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
  • 3,011
  • 3
  • 24
  • 50
4
votes
3 answers

How to send RealmObject in Bundle?

How to pass RealmObject through the Intents Bundle? Is there an way to write RealmObject to parcel? I don't want to use Serializable for know reasons.
Dawid Hyży
  • 3,151
  • 5
  • 23
  • 36
4
votes
0 answers

how to get an URI from a Bundle?

I got an Intent that takes a photo, after taking the photo I get the bundle with this.imagen = imageReturnedIntent; this.lol = imagen.getExtras(); I got my "extra" on the Bundle, but I need it in a Uri because after getting the "data" I send it to…
luthor
  • 85
  • 1
  • 5
3
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:…
3
votes
0 answers

Parcelable with inheritance in Kotlin- Base class properties not getting parcelized

I have a parent class in Kotlin like this open class Parent( var name: String, var dose: JsonElement?, val other: String?) { constructor(name: String, dose: JsonElement?) : this( name = name.toLowerCase(), dose = dose, other =…
Abhishek Bansal
  • 4,779
  • 3
  • 35
  • 60
3
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,229
  • 12
  • 36
  • 60
3
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…
3
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
  • 44,755
  • 49
  • 183
  • 309
3
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…
3
votes
1 answer

Retrieve android.intent.extra.EMAIL value from bundle

I created one app like email clients app such as Gmail. When user click on email address in another apps and choose my app from email sending apps in list appear on . The email content like email address , email subject and .... come to my app by…
sam nikzad
  • 1,017
  • 1
  • 16
  • 37
3
votes
0 answers

Error on startActivity, but only on android 7 devices

Since I updated my phone (Samsung Galaxy S7) to the new Android 7.0 two days ago I'm getting sporadically an error when running my app. It occurs sometimes (average every fifth time) when starting the Activity_C with startActivity:…
3
votes
4 answers

Activity launched from a service loses the "extra" from the bundle

Calling code (run in service): Intent textIntent = new Intent(this, TextActivity.class); textIntent.putExtra("text_seq", message.xfer.seq); textIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(textIntent); Called code (in…
fadedbee
  • 37,386
  • 39
  • 142
  • 236
1 2
3
18 19