我的问题很简单,我怎么能识别应用程序的第一个开始? 我认为它可以通过保存在RMS一定的价值和阅读它的应用程序启动时,并决定该怎么做来完成。
但是,是不是有更简单的解决方案吗?
我的问题很简单,我怎么能识别应用程序的第一个开始? 我认为它可以通过保存在RMS一定的价值和阅读它的应用程序启动时,并决定该怎么做来完成。
但是,是不是有更简单的解决方案吗?
有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))
}