Hello all,
I have a program that has some static data and auto-runs on startup so that the static data is created (including a reference to the instance of the program). I also create a phone listener and add it so that when a call is disconnected it fires. My phone listener upon disconnecting puts up a new screen which uses the static data but the problem is it sees it all as null and so breaks saying the application is already running in this process.
I use exactly the same code for the creation of the screen to access the screen manually from the ribbon and it works perfectly fine.
It's not just the phone listener either, i've tried the phonelog listener and the same story.
Here's the jist of my code
Code:
public class Program extends UiApplication
{
private static Program _instance = null;
private static Model _model;
public static Program getInstance()
{
if (_instance == null)
_instance = new Program();
return _instance;
}
private Program()
{
_model = new Model();
PhoneLogs.addListener(new MyPhoneLogListener());
}
public static getModel()
{
return _model;
}
public static void main(String[] args)
{
Program.getInstance().enterEventDispatcher();
}
class MyPhoneLogListener implements PhoneLogListener
{
public void callLogAdded(CallLog cl)
{
UiApplication.getUiApplication().pushScreen(new MyScreen());
}
public void callLogRemoved(CallLog cl)
{
}
public void callLogUpdated(CallLog cl, CallLog oldCl)
{
}
public void reset()
{
}
}
}
Code:
class MyScreen extends MainScreen
{
Model _model;
public MyScreen()
{
super();
_model = Program.getModel();
// breaks here as it thinks that _instance in Program is null (even though
// it's already been created and it's static) and so tries to create it again
// then throws the error that the application already exists in this process
}
}
Anyone have any idea why this is happening?