Global variables - Android with a Globally accessible class in all activities

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I am having some trouble with sharing a globalVaribale class:

here is my class:

public class GlobalObjects extends Application {

private Context context;

public GlobalObjects(Context context) {
    this.context = context;
}

// Variables

private Network network;


// Getters And Setters

public Context getContext() {
    return context;
}

public void setContext(Context context) {
    this.context = context;
}

public Network getNetwork() {
    return network;
}

public void setNetwork(Network network) {
    this.network = network;
}
}

and here is my android manifest file:

   <application
    android:name="GlobalObjects"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

I have added the global object to the already existing application tag. But when I run the class it gives errors:

08-07 21:19:58.867: E/AndroidRuntime(3588): FATAL EXCEPTION: main
08-07 21:19:58.867: E/AndroidRuntime(3588): java.lang.RuntimeException: Unable to instantiate application com.example.electronicmenu.GlobalObjects: java.lang.ClassNotFoundException: com.example.electronicmenu.GlobalObjects

Answers

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/18112112/android-with-a-globally-accessible-class-in-all-activities

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils