【问题标题】:J2me detecting first start of applicationJ2me 检测应用程序的首次启动
【发布时间】:2012-05-08 03:58:47
【问题描述】:

我的问题很简单,如何识别应用程序的首次启动?我认为可以通过在 RMS 中保存一些值并在应用启动时读取它并决定做什么来完成。

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

【问题讨论】:

    标签: java java-me midp


    【解决方案1】:

    据我所知,没有更简单的方法,但无论如何都非常简单;

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-19
      • 1970-01-01
      • 2010-09-23
      • 1970-01-01
      • 2012-10-10
      • 2020-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多