Recently in the writing of an Android project, I wrote a androidapplication global variable, which wrote some methods to get the application package name and system, but I every time when the call is an empty exception, I think I should write all write, what singleton mode, has not found the reason, Take the time to study today, it turns out I made a mistake before, originally application and Activity,service is a system component of the Android framework, When the Android program starts, the system creates a Application object to store some information about the system. Usually we do not need to specify a application, then the system will automatically help us create. By opening the manifest file for each application, you can see that the activity is included in the application tag:
, here I did not give my application of the application to specify an object, so I entered the Application object I wrote is also empty, so as long as it is added here, I hope that the same people who have encountered such problems have helped, there are problems we can exchange.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android App application global variable access