How to Generate Android App Bundle (Signed and Debug)

App Bundle reduces the number of Android apks that needs to be generated, released and maintained. It is the new format that is build and uploaded to the Google Play Store. Google takes the bundle, generates appropriate apks based on the device architectures, screen densities, device languages and serves to the device as a part of Dynamic Delivery.

As a first step, lets generate a debug version of the app bundle and after that lets take a look at generating a released version of the app bundle. Generated app bundles are in .aab format.
Generate Debug Version:
1) Click on the Build menu option at the top, select the Build Bundle(s)/APK(s) and click Build Bundle(s).

Debug app bundle is generated and saved to ../app/build/outputs/bundle/debug/app.aab.

Generate Release Version:
1) Similar to the step followed while generating a debug version, click on the Build menu option.

2) It opens a dialog with options to build a bundle or an apk. Select the Android App Bundle option and click Next.


How to Migrate to AndroidX

In this article, we will refactor an existing support library project to Androidx. The package names, dependency names change and rest (like class names, method names) stays the same.
1) Click Refactor and then Migrate to AndroidX.

2) Click Migrate and make sure the back up option is selected.

3) Provide a location to save the backup of the entire project.

4) Verify the dependencies, the package names that are getting refactored and then finally Click Refactor.

Once finished, you can see the updated package names and dependency names. In addition to that, the Refactor option adds android.useAndroidX=true and android.enableJetifier=true to file. This converts the support library package names of the non-convert third-party libraries.
This process is fairly simple but there might be issues faced and the refactor may fail, so backing up the project or tracking the changes using git is necessary to avoid the project loss.

How to Migrate to Material Components (MDC)

Material Components (MDC) is built by developers at Google (separate from the Android team) with intentions of helping developers build Material Design in their web and mobile-based apps. This is the next iteration of Material Design released in 2014.
Follow the steps mentioned below to migrate the app to use the Material Design Components instead of AppCompat or default UI components.
1) Add the Material Components dependency to the module level build.gradle file.
implementation ''
2) In the styles.xml Replace AppCompat with MaterialComponents. If you performed the action successfully then your base application theme will look like this.
    <!-- Base application theme. -->     <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">         <item name="colorPrimary">@color/colorPrimary</item>         <item name="colorPrimaryDark">@color/…

Intro to Activity and Its Lifecycle

Activity is one of the four components of Android and it provides an interface to the user so that they can interact with the views.
Simply, activity is a single screen in an app. It could be a maps screen in the Google Maps app or user profiles in the Facebook app or contacts list screen in the Contacts app and settings screen in the Settings app. Most apps contain multiple screens and inside these screens, you have buttons, edit texts, check boxes, list items and more with which you can interact.

Activities should be declared in the manifest file and of all the activities in an app, only one activity will be the launcher activity.
How to create an Activity: 1) Right click on the app module, hover over New option and then on the Activity.

2) Now, select the Basic Activity and change the activity name to Second Activity.

3) Click Finish to create the Second Activity.

You'll see one method is overridden it's named onCreate. The activity is automatically added to the AndroidMani…

Convert a Content Provider Cursor to JSON

This is a short article where we will read the data from the content provider and convert it to JSON. So, Let's query the SMS table and get a reference to the cursor.
// Query the sms tableval cursor = context?.contentResolver?.query( Telephony.Sms.Inbox.CONTENT_URI, null, null, null, null )
With the cursor in hand, loop through it to read the rows and columns.
cursor?.use { // Total number of columns in the table Log.v(TAG, "Column Count: ${it.columnCount}") // Total number of rows in the table Log.v(TAG, "Row Count: ${it.count}") // Move to the first item it.moveToFirst() // Temporary json variable that contains all the rows and their valuesval rowJson = JSONArray() // Loop through the rowsdo { // Temporary json variable that contains all the columns and their valesval columnJson = JSONObject() // Loop through the columns it.columnNames.forEachIndexed { i, columnName -> // Add the …

Cronet - Chromium Network Stack for Android

Cronet is a Chromium network stack used internally by Google inside its mobile apps for reliable network requests. Recently, Google made the library available for Android, IOS but the network stack has been part of Chrome web browser for a long time. 
Using Cronet, the requests can be given priorities and responses can be cached in memory or on the disk. Once set the priorities, the server can decide the order to execute the requests and once cached, the future requests are fetched automatically from the cache.
Cronet requests are asynchronous which means it doesn't even block the worker threads. This network stack provides support for HTTP, HTTP2, and QUIC (Quick UDP Internet Connections) protocols. It usesBrotli Compressed Data Formatto perform lossless compression.
Cronet automatically sets the request type to GET or POST based on the presence of the request body or the developer can always manually set the request type to their preferred choice.

Let's Create a Simple Reque…

How to Read Metadata from AndriodManifest File

Metadata tags are key-value pairs and one of the decent ways to access the API keys from the libraries. They are added to the AndroidManifest.xml under the application tag and are available through the PackageManager . If you have worked with third-party libraries or even with App shortcuts, Downloadable Fonts, Firebase MLKit, you may have come across metadata tags.
In the article, let’s add the metadata tags to the app module’s Manifest file and read the metadata key-values and the key-resource from a library module both in kotlin and java. Add meta-data: Add metadata to the app module's AndroidManifest.xml file under the application tag. You can add as many metadata elements as you want and you can also add metadata under the activity, service, broadcast receiver, content provider tags.