Create an Application class in Android

In Android, Application is the base class in Android which contains all Android components like Activities, Services, Broadcast Receivers, Content Providers, etc inside it. For a better understanding, you can consider it as the head of a family and all other family members are components. If you can open the Manifest.xml file from any of the android application, then you can able to see the application tag will be the top (inside manifest tag) and all activities and other components will be inside the application tag.

 

Application class is helpful to handle global initializations. If you will use any third party library like GreenDAO, fresco, ACRA, etc, then you have to initialize them inside the application class.

So let’s create an Application class.

 

Just create one Java class the same as how you are creating an Activity and extend the android.app.Application instead of extending Activity/AppCompatActivity.  Now override the onCreate method the same as how you are doing in Activity. And that’s all.

 

 

Now go to your Manifest.xml file and add this class in your application tag as the name.

 

 

If you will see properly, then inside application tag the first line is nothing but the name of the application which links to our MyApplication.java class( android:name=”.MyApplication”) And here we are finishing our final touch of creating the Application class.

 

      Gsmprix.com Mobile Phone Reviews, News Specifications



      Compare items
      • Total (0)
      Compare