public class App extends Object
init(Context)
method must be called before use.BaseApplication
Modifier and Type | Method and Description |
---|---|
String |
getApplicationLabel()
Get the application label of this application.
|
android.content.Context |
getContext()
Get the application context.
|
String |
getCountry()
Get the current country.
|
Preferences |
getDefaultPreferences()
Get the
Preferences instance that wraps the default shared
preferences. |
static App |
getInstance()
Get the singleton instance of this class.
|
String |
getLanguage()
Get the current language.
|
Locale |
getLocale()
Get the current locale.
|
Preferences |
getPreferences()
Get the
Preferences instance that is supposed to be used
globally for this application. |
String |
getVersionName()
Get the version name of this application.
|
static App |
init(android.content.Context context)
Initialize this class.
|
boolean |
isRestarting()
Check whether this application is in the process of restart.
|
boolean |
isStopping()
Check whether this application is in the process of termination.
|
void |
setRestarting(boolean restarting)
Set the restart state of this application.
|
void |
setStopping(boolean stopping)
Set the termination state of this application.
|
public static App init(android.content.Context context)
getInstance()
method. Otherwise,
getInstance()
will throw IllegalStateException
.
It is recommended to call this static method in an implementation
of onCreate()
method of a subclass of Application
.
In the case, the subclass should be specified as the value
of android:name
attribute of application
tag in
AndroidManifest.xml
. The easiest way to do it is to use
BaseApplication
class whose onCreate()
method calls
App.init(this)
.
In particular, items below are performed.
java.net.preferIPv4Stack
" to true
if the system property is not set, and set
"java.net.preferIPv6Addresses
" to false
if the system property is not set. These are done as a
workaround against
Issue 9431. Without this workaround,
"java.net.SocketException: Bad address family
"
would be thrown on a device which does not support IPv6.
context
- The application context.App
that has been initialized
with the given context. getInstance()
will return
the same instance.IllegalArgumentException
- The argument is null.public static App getInstance()
init(Context)
method must be called before use of this method. Otherwise,
IllegalStateException
is thrown.public android.content.Context getContext()
init(Context)
is returned.public String getApplicationLabel()
PackageManager.getApplicationLabel()
.public String getVersionName()
PackageInfo.versionName
.public Preferences getPreferences()
Preferences
instance that is supposed to be used
globally for this application.Preferences
instance which holds a private (MODE_PRIVATE
)
SharedPreferences
instance which has been initialized with the application
context passed to init(Context)
method and the
application name as the SharedPreferences instance's name.public Preferences getDefaultPreferences()
Preferences
instance that wraps the default shared
preferences.Preferences
instance that wraps the default shared
preferences.public Locale getLocale()
public String getLanguage()
public String getCountry()
public boolean isStopping()
public void setStopping(boolean stopping)
public boolean isRestarting()
public void setRestarting(boolean restarting)
Copyright © 2016. All rights reserved.