4

I did a little app in J2ME, it just open the browser with a target link.

Nevertheless, it works in some models of phones and in others it does not.

It works in:

  • BlackBerry 9000.
  • Nokia n97.
  • BlackBerry Javeline 8900

Id does not work in:

  • Nokia e71 : it install the app, but the browser does not open.
  • Nokia n81 : Idem.
  • Samsung f330: it can not install the app.
  • BB 9800 : install OK. Browser with page OK. When closing the app it re-start. (maybe using some kind of "finish()" in JavaME would help?)

I don't know why it works in some phones and in others don't. In theory, it should work with every phone with support of J2ME (JavaME).

EDIT: Here is the relevant code.

protected void startApp() throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    boolean mustExit = false;
    try {

        /**
         * mustExit - Boolean
         * 
         * Some MIDP platforms are more restricted than others.
         * For example, some don't support concurrent processing,
         * so the MIDlet must exit before the platform can honor
         * a service request.
         * 
         * If <true> destroy the app. So the browser
         * can start.
         */
        mustExit = platformRequest("http://www.stackoverflow.com");
    } catch (ConnectionNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if(mustExit){
        destroyApp(true);
        notifyDestroyed();
    }

    //Display.getDisplay(this).setCurrent(timeAlert);

}
  • It is hard to tell what's wrong with the application if you haven't seen its code. Please, post it. – Malcolm Mar 08 '12 at 21:00

1 Answers1

5

You shouldn't be doing stuff like platformRequest in a lifecycle method such as startApp(). It's an asynchronous operation, it needs to ask the user for permission etc. This should not be done on the system thread.

Methods called on the system thread should return as close to immediately as possible, because the thread will likely be in charge of doing other stuff like screen redrawing, or processing user input. platformRequest is a blocking operation and will cause your device to freeze.

Some devices can handle this better than others which is why you're seeing the discrepancy.

Kick off a new thread to do the platformRequest and all should be well; you can start your new thread pretty much anywhere.

funkybro
  • 8,432
  • 6
  • 39
  • 52
  • is there another instruction that should I use then? Could you post it, if possible? –  Mar 09 '12 at 13:35
  • 1
    Like I said, do it in a new thread: `new Thread(new Runnable() { public void run() { platformRequest("http://www.stackoverflow.com"); } }).start();` – funkybro Mar 09 '12 at 13:56
  • Thank you. I will try to implement it. But could you explain a little bit the answer (editing it). Sorry for my "newbiness". I'm just starting with mobile dev. Why It should not be done in the system thread. Why not using `platformRequest` in `startApp()` and what makes that a device can handle or not this function? In which part of the device cycle should I put the thread you are suggesting? I mean, which is the "differentiator". –  Mar 09 '12 at 15:02