Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
cwong15
Posts: 193
Registered: ‎02-27-2009
My Device: Not Specified
Accepted Solution

Generating GUIDs with Eclipse plugin

Some APIs -- such as the global event listeners and persistence APIs -- expect you to provide a GUID. Code samples generally show a hard-coded long literal. I imagine there would be some chance of ID collisions. How does one normally generate such GUIDs when using Eclipse? Thanks.
Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,677
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: Generating GUIDs with Eclipse plugin

The recommended approach is to use your package name and classed name:

 

Example:

 

com.mycompany.mypackage.myclass

 

This example equates to: 0x9fd1c13aff6c669dL

 

To convert a string to a long value highlight the string in the BlackBerry JDE or Eclipse, right click and then choose "Convert String to Long".  Note that if you are using Eclipse this feature requires the BlackBerry JDE Plug-in for Eclipse be installed.

 

 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
williammathies
Posts: 1
Registered: ‎03-19-2009
My Device: Not Specified

Re: Generating GUIDs with Eclipse plugin

Mark,

 

Is there a way to do this programitically? It would be nice to be able to do something like:

   

static long persistantKey = "com.rim.samples.device.helloworld".hashCode();

 

However, this only produces an integer not a long so I think it is not as unique.

 

Thanks.

 

- Will Mathies

Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Generating GUIDs with Eclipse plugin

/    static final long pik=
//            StringUtilities.stringHashToLong(pkg+".history.thingy");

Please use plain text.