2

I am developing an application where I want to integrate the SQL database in it. As far my code works fine. I made the application auto-run on startup and I check immediately for SDCard presence. If present I will create the database on SDCard and if not I will create it on device.

The problem is that when the application is auto-run, it will start before the device locates the SDCard, so I am always unable to detect if the SDCard is present.

What listener should I use to know that the device is completely turned on?

gnat
  • 6,213
  • 108
  • 53
  • 73
Farid Farhat
  • 2,300
  • 1
  • 16
  • 29

1 Answers1

5

SystemListener will do the job. This is how I usually do it:

    public class MyApp extends Application implements SystemListener {

        public static void main(String[] args){
            MyApp app = new MyApp();
            if (ApplicationManager.getApplicationManager().inStartup()) {
                app.addSystemListener(app);
                //wait for powerUp callback
            } else {
                app.startup();
            }
        }

        public void powerUp() {
            removeSystemListener(this);
            startup();      
        }

        private void startup(){
            //Perform initialization here, most typically show first screen and stuff.
        }

        // Remaining SystemListener callbacks not shown for brevity
    }
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
  • This will not do the job because powerUp is called even before SDCard is detected. Any other methods? Thank you – Farid Farhat Oct 19 '12 at 10:11
  • Sorry, I forgot about the SDCard thing and focused on the startup detection. Yes, you can try FileSystemListener (http://www.blackberry.com/developers/docs/7.0.0api/javax/microedition/io/file/FileSystemListener.html) – Mister Smith Oct 19 '12 at 12:15
  • 2
    BTW you should register a listener through FileSystemRegistry class. – Mister Smith Oct 19 '12 at 12:17