I am trying to setup and global variable, but I my app fails after adding the following line to my AndroidManifest.xml
<application android:name=".MyApp"
android:icon="@drawable/icon"
android:label="@string/app_name">
I am using the following code as well:
Class: package com.mynamecompany.datahelp;
import android.app.Application;
class MyApp extends Application {
private String myState;
public String getState(){
return myState;
}
public void setState(String s){
myState = s;
}
}
Usage:
MyApp appState = ((MyApp)getApplicationContext());
String state = appState.getState();
Toast.makeText(getApplicationContext(), "My Value-" + state, Toast.LENGTH_SHORT).show();
appState.setState("Test");
Toast.makeText(getApplicationContext(), "My Value-" + appState.getState(), Toast.LENGTH_SHORT).show();
The program starts and errors immediately on the Splash screen before the usage code can be called further in the program, on a different Activity.
Any ideas?