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
Posts: 52
Registered: ‎07-17-2008
My Device: Not Specified

Supporting multiple OS versions

[ Edited ]

We have been building our application using JDE 4.3 and so far it has worked fine on handhelds with software versions 4.2x and 4.3x.  In the next release of our app, we would like to use couple of  JDE 4.3 specific methods while still supporting 4.2x handhelds.  I thought about using if condition around these special method calls, so that they get invoked only if the software version at runtime is 4.3x or better.  While searching through this forum recently, I found out that a COD file buit using a specific JDE version MAY NOT work on handhelds running other version of the OS software.  Does this mean  we are required to maintain seperate source files for each OS version we are intending to support? 

 

I could use the Java equivalant of C++'s [ifdef] nightmare.  (http://weblogs.java.net/blog/schaefa/archive/2005/01/how_to_do_condi_1.html). I know this does not sound like a pleasant choice.  Besides, in this case, the Ant copy-filter feature is not going to work as is.  I will have to write a custom Ant task to extent copy-filter functionality.

 

Having seperate source file copies  seems to  be the only other approach, which will adversly affect the maintainability of the application.

 

Is there any other recommended approach to deal with this situation?

 

Thanks in advance...

 

 

-Ashwath

 

 

 

Message Edited by akirekadu on 07-30-2008 06:17 PM
Message Edited by akirekadu on 07-30-2008 06:31 PM
Developer
Posts: 191
Registered: ‎04-03-2008
My Device: Bold 9700

Re: Supporting multiple OS versions

This was recently discussed here.
Developer
Posts: 52
Registered: ‎07-17-2008
My Device: Not Specified

Re: Supporting multiple OS versions

[ Edited ]

Thanks.  Can't figure out how I missed that.  Your solutions seems to be one of the best options currently available.   Kudos!

 

I am really curious to know what is RIM's recommended way to handle this situation.  I am sure they face this problem more often than we do Smiley Wink

Message Edited by akirekadu on 07-30-2008 07:53 PM
Message Edited by akirekadu on 07-30-2008 07:53 PM
Highlighted
New Developer
Posts: 5
Registered: ‎07-14-2008
My Device: Not Specified

Re: Supporting multiple OS versions

How about a class Factory?    Its a bit more boilerplate code, but you can avoid scripting.

 

Include the appropriate concrete classes in the associated JDE projects.  For instance, you want to determine if the device has a camera:

 

 

/// YourApp.java

DeviceCaps caps = DeviceCaps.getCaps();

if ( caps.hasCamera() )

{

   

  ....

}

 

 


 

///DeviceCaps.java  - include this in all projects

public abstract class DeviceCaps
{
    public abstract boolean hasCamera();
   
    public static DeviceCaps getCaps()
    throws Exception
    {
        DeviceCaps ret = null;
        
        // do magic to get firmware version... ( using a double for simplicity...)
        double version = 4.2;
        
        // flesh these out for each of your suported firmwares....

        if ( version >= 4.2 )
        {
            return (DeviceCaps) Class.forName("DeviceCaps42" ).newInstance();
        }
        else if ( version < 4.2 )
        {
            return (DeviceCaps) Class.forName("DeviceCaps40" ).newInstance();
        }
        
        return ret;
        
    }

 

/// DeviceCaps40.java (include this on JDE 4.0.X)

public class DeviceCaps40 extends DeviceCaps
{
    public boolean hasCamera()
    {
        return false;
    }
}

 

/// DevceCaps42.java (include this on JDE 4.2.X projects)

public class DeviceCaps42 extends DeviceCaps
{
    public boolean hasCamera()
    {
        return net.rim.device.api.system.DeviceInfo.hasCamera();
    }
}

 

 

 

 

Regular Contributor
Posts: 71
Registered: ‎03-24-2010
My Device: 9550
My Carrier: Vodaphone

Re: Supporting multiple OS versions

I tested with Class.forname() as suggested.

However, it does not work.

When application starts, BB will load all class included in COD file and it will raise Class XXX not found exception.

 

So I choose to use preprocessor

//#preprocess

//#ifdef

//#else

//#endif