J2ME应用程序检测的第一起始(J2me detecting first start of appl

2019-07-29 07:25发布

我的问题很简单,我怎么能识别应用程序的第一个开始? 我认为它可以通过保存在RMS一定的价值和阅读它的应用程序启动时,并决定该怎么做来完成。

但是,是不是有更简单的解决方案吗?

Answer 1:

有is'nt一个更简单的方法,据我所知,但这是很容易反正;

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


文章来源: J2me detecting first start of application