1

I am writing an application. In that application I have an instance that I only want to happen the first time that the application is opened. I want to know how to write something in Java that will only make that instance happen that first time. Like a registration code or something like that.

Daniel
  • 11
  • 1

3 Answers3

5

PersistentStore -- create a Singleton. The Blackberry dev forums have an excellent singleton approach that utilizes the RuntimeStore, but that does not cross restarts, PersistentStore does.

Dan
  • 1,002
  • 12
  • 24
4

"Item 3: Enforce the Singleton Property with a Private Constructor or an enum Type"—Joshua Bloch, Effective Java.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 2
    PersistentStore -- create a Singleton. The Blackberry dev forums have an excellent singleton approach that utilizes the RuntimeStore, but that does not cross restarts, PersistentStore does. – Dan Apr 20 '11 at 02:45
  • @Dan: Thanks for commenting on this. IIUC, [`PersistentStore`](http://www.blackberry.com/developers/docs/3.7api/net/rim/device/api/system/PersistentStore.html) is particularly apropos to the question. It might be worth making it a separate answer. – trashgod Apr 20 '11 at 03:00
  • 1
    thx trashgod, newb thing -- just spreading the luv an 4getting about status ;) – Dan Apr 20 '11 at 03:04
0

i know nothing about blackberry, but this seems like it could be answered with a generic answer:

set a flag somewhere

mkoryak
  • 57,086
  • 61
  • 201
  • 257