简体   繁体   English

如何在Blackberry Java中只运行一次方法?

[英]How to run a method only once in Blackberry Java?

I am developing an application in Blackberry. 我正在开发Blackberry中的应用程序。 I have to write a code or a method that runs only once. 我必须编写一个只运行一次的代码或方法。 The method does an action on creating the database. 该方法对创建数据库执行操作。 Something similar to Oncreate method in Android. 与Android中的Oncreate方法类似的东西。 Help of any sort is appreciated. 任何形式的帮助表示赞赏。

A Y. 一个Y.

Create a singleton class and call the method from singleton class private constructor, or maintain a global flag and check that flag on method call. 创建一个单例类并从singleton类私有构造函数中调用该方法,或者维护一个全局标志并在方法调用上检查该标志。

There are many other ways but calling of a method is on you, and you can do any way for this. 还有很多其他的方法,但是你可以使用方法调用,你可以为此做任何事情。

If you want to run that code in single time of application life then, 如果你想在单次应用程序生命中运行该代码,那么,

use persistent store and add one flag, change the flag value after successfully running that code . 使用持久存储并添加一个标志,在成功运行该代码后更改标志值。

Both BlackBerry and Android provide the Persistent storage. BlackBerry和Android都提供持久存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM