I'm developing an app for Blackberry on OS 5. I'm trying to have some previously initialized variables accessed when a call is successfully made. However, the variables don't hold their value and I can't find why.
When the app gets started, testVariable is set to 5, everything works as expected. However, when I try to access the variable from the callConnected event, it is back at 0. Even if I put the variable inside the PhoneEvents class it still goes back to 0. It has one value for PhoneEvents and another for the screen. Shouldn't these variable have only one value given that it's not an instance variable? What am I doing wrong? Is there any other way to have a variable accessed from the PhoneEvents class and the TestScreen class and having it keep its value? Thanks in advance.
public class TestApp extends UiApplication {
public TestApp() {
TestScreen screen = new TestScreen();
UiApplication.getUiApplication().pushScreen(screen);
}
public static void main(String[] args) {
Phone.addPhoneListener(new PhoneEvents());
TestApp app = new TestApp();
app.enterEventDispatcher();
}
}
// The main screen.
public class TestScreen extends MainScreen {
public TestScreen() {
this.setTitle("Test");
GlobalClass.testVariable = 5;
}
}
// A public static holding a variable I want to have access to.
public class GlobalClass {
public static int testVariable;
}
// The method that gets called when a call is made.
public class PhoneEvents implements PhoneListener {
public void callConnected(int callId) {
int x = GlobalClass.testVariable;
}
}