×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Gdansk, Poland
    Posts
    139

    How to detect if code is running in the N97 emulator

    How can I programatically detect if my code is running in the N97 emulator or in one of the real S60r5 phones?

    In case it is the emulator, I'd like to behave a bit differently ( different debugging )
    Last edited by Utumno; 2010-05-16 at 16:41.

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How to detect if code is running in the N97 emulator

    My recommended technique for including debugging code is not to try to identify the execution environment, but simply to build differently.

    For example, create a class:

    Code:
    public class Debug {
        public static final boolean ON = true;
    }
    Then...

    Code:
    if (Debug.ON) {
        // do some debug stuff
    }
    This way, when you build with Debug.ON = false, the сompiler will automatically remove the debug code from the .class files (reducing code size).

    If you want something more exotic, extend the technique...

    Code:
    public class Debug {
        // don't change these
        public static final int OFF = 0;
        public static final int EMULATOR = 1;
        public static final int DEVICE = 2;
    
        // change this to select build options
        public static final int MODE = OFF;
    }
    Code:
    if (Debug.MODE == Debug.EMULATOR) {
        // do some emulator-only debug stuff
    }
    Rules:

    1. If a variable is "static final", has a primitive type (like int or boolean), and is initialized from a literal (like "5" or "true") (or an expression that can be computed at compile time), then it's value will be in-lined by the compiler.

    2. Where an "if" expression is a constant "false", then the "if" and its contents will be removed by the compiler.

    3. Where an "if" expression is a constant "true", the "if" and its expression will be removed, but the body will be left alone.

    4. Unreferenced classes (such as those that contain only constants, like my Debug example classes) will be removed from the build by Proguard. If any debugging code has been excluded by rule (2) above, then any methods (like assertion or debug output methods) that become now unreferenced will be removed by Proguard.

    Graham.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    Gdansk, Poland
    Posts
    139

    Re: How to detect if code is running in the N97 emulator

    Well yes, currently I do have it exactly like you say. But I keep forgetting to change the value of this one boolean variable to 'EMULATOR' or 'DEVICE' and that slows me down. I was hoping I could completely automatize this.
    Of course, when doing the final release, I would disable this as not to slow down the code.

Similar Threads

  1. Nokia N97 SDK - beta - released . Feedback welcomed.
    By Nokia Ron in forum Symbian Tools & SDKs
    Replies: 34
    Last Post: 2009-07-28, 06:20
  2. N97 Emulator in SDK issue - Today, 04:22
    By sam_bakki in forum General Development Questions
    Replies: 0
    Last Post: 2009-06-17, 09:15
  3. Replies: 5
    Last Post: 2007-05-22, 06:25
  4. Emulator did not start with error: Symbian error code: -10509
    By cvraiden in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2006-12-05, 21:52
  5. Link errors when trying to Display bitmap
    By Bkc82 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2006-01-16, 22:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×