I'm trying to share two ArrayLists across the various activities in my application, using the scheme explained here: How to declare global variables in Android?.
Here's my application subclass:
public class GlobalVars extends Application{
ArrayList<Player> players = new ArrayList<Player>();
ArrayList<String> playerNames = new ArrayList<String>();
public ArrayList<Player> getPlayers(){
return players;
}
public ArrayList<String> getPlayerNames(){
return playerNames;
}
public void setPlayers(ArrayList<Player> p){
players = p;
}
public void setPlayerNames(ArrayList<String> pn){
playerNames = pn;
}
}
And used the code:
GlobalVars gv = (GlobalVars)getApplicationContext();
players = gv.getPlayers();
playerNames = gv.getPlayerNames();
To access these variables. The first line there where I define gv throws a classcastexception. Anyone know why?
Here's the code I added to the manifest:
<application android:name="com.myname.GlobalVars"
android:icon="@drawable/icon"
android:label="@string/app_name"></application>
edit:for clarification, here is my entire manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myname.bpstattracker" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BPStatTracker" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BPSTAdd"></activity>
<activity android:name=".OneOrThree"></activity>
<activity android:name=".SixOrTen"></activity>
</application>
<application android:name="com.myname.GlobalVars"
android:icon="@drawable/icon" android:label="@string/app_name">
</application>
</manifest>