App bundles are publishing format, whereas APK (Android application Package) is the packaging format which eventually will be installed on device. Google uses app bundle to generate and serve optimized APKs for each user's device configuration, so they download only the code and resources they need to run your app.
The default location is app/build/outputs/bundle/release .
Step 1: Go to Android Studio -> Build ->Generate Signed Bundle. Select Android App Bundle on the pop screen and select Next. Step 2: Enter the KeyStore path where the KeyStore is stored or Create a new KeyStore as seen below. Step 4: Select the release mode from the list and select finish.
If you cannot open your BUNDLE file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a BUNDLE file directly in the browser: Just drag the file onto this browser window and drop it.
Bundles are generally used for passing data between various Android activities. It depends on you what type of values you want to pass, but bundles can hold all types of values and pass them to the new activity.
You can use it like this:
Intent intent = new...
Intent(getApplicationContext(), SecondActivity.class);
intent.putExtra("myKey", AnyValue);
startActivity(intent);
You can get the passed values by doing:
Bundle extras = intent.getExtras();
String tmp = extras.getString("myKey");
You can find more info at:
android-using-bundle-for-sharing-variables and
Passing-Bundles-Around-Activities
Pass data between activities by using Bundle
and Intent
objects.
Your first create a Bundle
object
Bundle b = new Bundle();
Then, associate the string data stored in anystring
with bundle key "myname"
b.putString("myname", anystring);
Now, create an Intent
object
Intent in = new Intent(getApplicationContext(), secondActivity.class);
Pass bundle object b
to the intent
in.putExtras(b);
and start second activity
startActivity(in);
In the second activity, we have to access the data passed from the first activity
Intent in = getIntent();
Now, you need to get the data from the bundle
Bundle b = in.getExtras();
Finally, get the value of the string data associated with key named "myname"
String s = b.getString("myname");
I have to add that bundles are used by activities to pass data to themselves in the future.
When the screen rotates, or when another activity is started, the method protected void onSaveInstanceState(Bundle outState)
is invoked, and the activity is destroyed. Later, another instance of the activity is created, and public void onCreate(Bundle savedInstanceState)
is called. When the first instance of activity is created, the bundle is null; and if the bundle is not null, the activity continues some business started by its predecessor.
Android automatically saves the text in text fields, but it does not save everything, and subtle bugs sometimes appear.
The most common anti-pattern, though, is assuming that onCreate()
does just initialization. It is wrong, because it also must restore the state.
There is an option to disable this "re-create activity on rotation" behavior, but it will not prevent restart-related bugs, it will just make them more difficult to mention.
Note also that the only method whose call is guaranteed when the activity is going to be destroyed is onPause()
. (See the activity life cycle graph in the docs.)
Update: When it comes to Android, there are two completely unrelated meanings to the term "bundle". One is detailed in my original answer below. The other is an app bundle. This is a newer archive file format (ending in .aap) that contains an Android app plus some additional metadata. You can upload an app bundle file instead of an application APK file to distribute your app through Google Play. App bundles have certain advantages over .apk files, but may not be compatible with other app stores (such as the Amazon App Store). These advantages are described in the documentation link included in my original answer.
Original answer:
A Bundle
is very much like a Java Map
object that maps String
keys to values. It's used to pass information between activities and other application components. It's also used by the framework to capture and restore state information.
The reason Android doesn't use plain old Map
objects for this is that Map
is too flexible; it can contain objects (such as, say, I/O streams) that cannot be serialized. The Bundle
API restricts the types of objects that can be added to a bundle in such a way that the bundle's contents are guaranteed to be serializable. The Android framework relies on this property.
I suggest that you read the documentation on Application Fundamentals. This explains, among other things, what bundles and intents are and what they are used for.
Bundles can be used to send arbitrary data from one activity to another by way of Intents. When you broadcast an Intent, interested Activities (and other BroadcastRecievers) will be notified of this. An intent can contain a Bundle so that you can send extra data along with the Intent.
Bundles are key-value mappings, so in a way they are like a Hash, but they are not strictly limited to a single String / Foo object mapping. Note that only certain data types are considered "Parcelable" and they are explicitly spelled out in the Bundle API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With