J2me检测首次启动应用程序 [英] J2me detecting first start of application

查看:144
本文介绍了J2me检测首次启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

据我所知,目前还没有一种更简单的方法,但无论如何这都很简单;

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

这篇关于J2me检测首次启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆