J2me detecting first start of application

白昼怎懂夜的黑 提交于 2019-12-20 07:08:26

问题


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?


回答1:


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))
    }


来源:https://stackoverflow.com/questions/10480413/j2me-detecting-first-start-of-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!