BidVertiser

Categories

Follow Us @web_learners

BidVertiser

Monday, August 10, 2020

How to Show Exit Dialog in Android App || Exit Dialog on Home Screen

August 10, 2020 0 Comments

 Hi, In the previous post we have learned How to Show Exit Dialogue on Splash Screen in Webview App. Today we will learn How to show Exit Dialog in Home Screen (Main Activity). Let's Start.

As we will show Exit dialog in MainActivity.java, so we will set a function onBackPressed().In that onBackPressed() function we will take an if-else condition.

Code:


The "if" condition will be if our website or app can go back then it will go to the previous page,  else it will show Exit dialog. And in the exit dialog, there will be a message, such as "Do you want to Exit?" or anything you want to show to your users.


And there will also two buttons in the Exit dialog, One is the "Yes" button, another one is the "No" Button. Then we have to set "OnClickListener" on "Yes" and "No" both button. In that OnClickListener, we will define what will happen after the user clicks on buttons.


After that, we will set if the user clicks on the "yes" button app will Exit successfully. And if the users click on the "No" button the user will stay on the current page. Then have to show the alert dialog.


So all the code together will be:

Code:
 

And see the below code so that you can understand where you have put the above Exit Dialog code.


Code:
 


Now you can run your project. You can see below the image we have successfully added Exit dialog on Home Screen. Exit dialog working perfectly.


That's it. Thank you.

Monday, August 3, 2020

How to solve Manifest merger failed problem in Android Studio

August 03, 2020 0 Comments
Hi, In the last post we have learned that How to Restore Suspended Webview Apps on Google Play. Today we are going to learn How to solve "Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-20:19 to override." problem in Android Studio.



For solving the Manifest merger failed problem,  it has two methods to solve it.  Two methods are below:

The first method is:
1. Migrate your project to AndroidX project.

The second method is:
2. Don't need to Migrate the project to the AndroidX project. Write code in the Manifest file.

How to Migrate your project to AndroidX project

If you are using old android studio libraries then you have to migrate your project to the AndroidX project. For migrating to the AndroidX project you have to add the following two lines into the "Gradle.properties" file in android studio.
Code:
 
First, go to the "Gradle.properties" file, then paste the above two lines. then click on "Sync Now" See the below images for better understanding.



 or you can migrate your project following way also. First, click on Refactor from the above menu in Android studio. Then select on Migrate to AndroidX. 

After that you will get a confirmation window, you need to click on migrate. It will ask you to do backup your project before migrating to AndroidX.you should do the backup. Then it will migrate your project to AndroidX.



Second Method:

If you don't want to migrate your project to the AndroidX project, you can follow this second method for migrating to the AndroidX project. You need to just write below two lines of code in the Manifest file in the Android studio.
Code:
 

See below image:




After that just "Sync" your project. You will see the error is gone. That's it. Thank you.

The video tutorial of  "How to solve Manifest merger failed problem in Android Studio" is here