We just need to set the value in this variable and get the value in any activity, even in service or broadcast receiver in the application context.Note: Every application has a context, and Android guarantees that application context will exist as an instance across the application.So we just need to specify our global class in the application tag of the Android manifest file of the application.Android will create an instance of that global class and make it available for the entire application context.We can get the object of that global class using following method:
Context.getApplicationContext()
Procedure to understandIn MyGlobalClass.java file creates get and set methods using a public variable.For instance:
Source CodeMyGlobalClass.java:
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: