Yes you can extends Applications class and store your data over there using Getter and setter.
So that your data will be retained throughout the Application.
public class SocketManager extends Application {
private static SocketManager singleton;
public int mBluetoothState;
public synchronized static SocketManager getInstance(Context context) {
if (null == singleton) {
singleton = new SocketManager();
}
return singleton;
}
public synchronized void setState(int state) {
mBluetoothState = state;
}
public synchronized int getState() {
return mBluetoothState;
}
}
Access it in Activity like :
SocketManager socketManager = SocketManager.getInstance(this);
socketManager.setState(10);
socketManager.getState();
Add your Application to Maanifest file like this :
<application
android:name=".SocketManager"
android:icon="@drawable/first_aid"
android:label="@string/app_name" >
<activity .... />
</application>
Edit :
You should add your class name that extends Application into Application Tag not on Activity Tag
For further refrence check this link