Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java J2me检测应用程序的首次启动_Java_Java Me_Midp - Fatal编程技术网

Java J2me检测应用程序的首次启动

Java J2me检测应用程序的首次启动,java,java-me,midp,Java,Java Me,Midp,我的问题很简单,如何识别申请的第一个开始?我认为可以通过在RMS中保存一些值,并在应用程序启动时读取这些值,然后决定要做什么来实现 但是,难道没有更简单的解决办法吗?据我所知,没有更简单的方法,但无论如何,这很容易 public static boolean isFirstRun() { RecordStore rs = null; try { rs = RecordStore.openRecordStore("myAwesomeR

我的问题很简单,如何识别申请的第一个开始?我认为可以通过在RMS中保存一些值,并在应用程序启动时读取这些值,然后决定要做什么来实现


但是,难道没有更简单的解决办法吗?

据我所知,没有更简单的方法,但无论如何,这很容易

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

据我所知,没有更简单的方法,但无论如何都很容易,

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