Android Custom Application global variables cannot be converted to type. android global variables
Today, I got a global variable AppContext, but the following error has always occurred. The original inherited Application must be declared in the configuration file.
Java. lang. runtimeException: Unable to start activity ComponentInfo {com. langteng. shiliao/com. langteng. shiliao. activity. mainActivity}: java. lang. classCastException: android. app. application cannot be cast to com. langteng. shiliao. until. appContext
Public class AppContext extends Application {
Public static final int NETTYPE_WIFI = 0x01;
Public static final int NETTYPE_CMWAP = 0x02;
Public static final int NETTYPE_CMNET = 0x03;
Public static final int PAGE_SIZE = 20; // default page size
Private static final int CACHE_TIME = 10*60000; // cache expiration time
.................................
Then, get an Application-type variable through getApplication () in the activity and convert it into a custom AppContext. As follows:
AppContext = (AppContext) getApplication ();
The result is a type conversion error during running.
After a long time, I found that the custom global Application must register the Declaration in AndroidManifest. xml:
<Application
Android: name = ". AppContext"
Android: icon = "@ drawable/ic_launcher"
Android: label = "@ string/app_name"
Android: theme = "@ style/AppTheme">
Global variables of android Application
No, you can declare it in the class instead of the onCreate method to use it in this Activity.
Public class GuessNumberActivity extends Activity {
Button btn1 = null;
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Btn1 = (Button) findViewById (R. id. btn1 );
}
// Used in other functions
Bt1.setOnClickListener (new Button. onClickListener (){.........});
Android inherits the Application class and puts some global variables in it. How can I clear the value of the variable?
Is the variable cleared? Is it 0 or something?