0

My question is simple how can I recognize first start of application? I think it can be accomplished by saving some value in RMS and reading it when app starts and decide what to do.

But isn't there simpler solution?

gnat
  • 6,213
  • 108
  • 53
  • 73
Joe
  • 1,270
  • 2
  • 17
  • 24

1 Answers1

3

There is'nt a simpler method as far as I know, but that's very easy anyway;

    public static boolean isFirstRun() {
        RecordStore rs = null;
        try {
            rs = RecordStore.openRecordStore("myAwesomeRecordStore", false); //check
            return false; //record store exists, so it's not our first run
        } catch (Exception e) {
            //RecordStoreNotFoundException, but we need to catch others anway
            try {
                rs = RecordStore.openRecordStore("myAwesomeRecordStore", true); //create
            } catch (Exception e1) {}
        }
        finally {
            if (rs != null) try {rs.closeRecordStore();} catch (Exception e) {}
        }
        return true; //so, record store did not exist and it was created (if no error occured (there shouldn't be any errors anyway))
    }
Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99