Skip to main content

How to automatically stop a Midlet when calling platformRequest(url)?

10 replies [Last post]
ccvo
Offline
Joined: 2007-04-18

I want to automatically exit my Midlet when calling platformRequest(url).
So, I have tried the following ways, but the Midlet is still running after calling platformRequest().

platformRequest(url);
destroyApp(true);

The Midlet is likely to be re-invoked by AMS.

Do anyone can help me?

Thanks,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15

Shouldn't you be using "notifyDestroyed();" along with "destroyApp(true);" !?

Also why not in "destroyApp(b);" put a condition to check if you want to terminate with a platform request such as

public void destroyApp(boolean _force)
{
if( doPReq)
{
platformRequest(url);
}
}

then in your other code have:
...
doPReq = true;
url = ;
notifyDestroyed();
....

Also another question are you sure AMS is re-entering the app? You might want to put a breakpoint in the startApp() method as this is where it should return to, and that your code is not just continuing at the destroyApp(b) statement, and that your method does not have a super.destryApp(b) call in it.

Regards,
-Shawn

ccvo
Offline
Joined: 2007-04-18

Yes, I put notifyDestroyed() in the destroyApp() method.

By many checkings, I reconigzed that although the app exits by calling destroyApp(b), but AMS is re-entering the app after doing platformRequest(url).

So, It may be no way to prevent from re-entering the app by AMS.

Any ideas?

Thanks,

sfitzjava
Offline
Joined: 2003-06-15

Try not putting notifyDestroyed() in destroyApp(b); That's not the standard way of programming that.

Also what is the re-entry point of the code startApp or at the return of platformRequest(url);
It would sound like the the device is not following the Specs. This is a MIDP2.0 device?

Try throwing the platformRequest call into a thread and then call notifyDestroyed() after you start that thread.

new Thread(new Runnable() { public void run(){ platformRequest(url);} }).start();
notifyDestroyed();

-Sf

ccvo
Offline
Joined: 2007-04-18

I am running on MIDP2.0 Emulator 2.5.1.
Following is the part of code:
...
public void startApp() {
Display.getDisplay(this).setCurrent(get_helloForm());
}

public void commandAction(Command command, Displayable displayable) {
if (command == exitCommand) {
exitMIDlet();
}else if (command == okCommand) {
try {
platformRequest("http://localhost:8084/App.jad");
} catch (ConnectionNotFoundException e) {}
exitMIDlet();
}
}

public void exitMIDlet() {
Display.getDisplay(this).setCurrent(null);
destroyApp(true);
notifyDestroyed();
}

public void pauseApp() {
exitMIDlet();
}
...

I change the code above to thread:
...
public void commandAction(Command command, Displayable displayable) {
if (command == exitCommand) {
exitMIDlet();
}else if (command == okCommand) {
new Thread(new Runnable() { public void run(){
try {
platformRequest("http://localhost:8084/App.jad");
} catch (ConnectionNotFoundException e) {}
} }).start();
exitMIDlet();
}
}
...

The both way is getting the same issue. The Midlet may exit when doing platformRequest(), and then it is re-invoked like we launch the app again.

sfitzjava
Offline
Joined: 2003-06-15

Hmmm.... This may be a problem with the emulator. Have you tried it on a real device.
I'm seeing the same problem in the emulator but on a real device it exits correctly.
However the device I'm using may support the platformRequest without having to exit.

What should work is to create a lock file using the RMS, and then check it at start up.
If it has a lock record then delete the record and exit, else it must be a clean start and
continue loading the app.

-Shawn

ccvo
Offline
Joined: 2007-04-18

I have not tried it on a real device, I will try.

Yes, you are right. I will try to use RMS.

Thank you so much for following this thread.

Now, do you think we can remove a Midlet suite which is already installed on the device by programming? I mean, without user convention, can a Midlet suite be removed by another running Midlet?

See you,

sfitzjava
Offline
Joined: 2003-06-15

That would not be possible. And that's a good thing. You wouldn't want a competitor to have in their code to go and remove your software would you!?! :)
However if you want your midlet to update itself....I think that is possible. And that is where the exiting a running midlet so that it can update is important...and I think that is why they re-enter the midlet as a fresh load when doing the platformRequest(http). I wonder if you would see different results if you did a platformRequest("tel://######"); since that could not be re-installing the midlet.

Also sadly JavaME isn't given enough power to allow an MIDlet to have a RemoveMe method and hook into the AMS allowing for an uninstall.

As a JavaME programmer you must remember that the users safety is priority #1, and I don't mind the user being informed of what my application is doing the first time or each time the app starts. It's when the phone companies and hardware vendors make it impossible for me to get to a feature even if the user is going to be informed of my actions or informing them every time they hit the same command that they have authorized, that chaps my hide.

However let me say one thing, that while JavaME is like skiing in a full body cast, if you let your mind free to think outside the box...no further outside...no keep going....almost there....go..go..go..
Then you sometimes can figure a way of doing something interesting.

Or use Window Mobile .net, because the phone companies let that trash, bug ridden, virus infected, STD of a language to run wide open. How stupid is that.

best regards,
-Shawn

ccvo
Offline
Joined: 2007-04-18

On my knowledge, J2ME does not have a mechanism which supports for uninstalling a Midlet suite. Users have just one way to remove a Midlet suite manually using JAM.

We know that almost destop applications are programmed to have a feature for uninstalling itself. So, why we do not have the power like that in J2ME???

Memory of mobile devices is limited, so in some cases, we want a Midlet suite to be installed on demand and be removed immediately after use.

Is it imposisble to do this?

alexlamsl
Offline
Joined: 2004-09-02

How about setting a boolean indicator field before calling platformRequest(), then in pauseApp() exit the MIDlet when the field is set?

ccvo
Offline
Joined: 2007-04-18

I have tried this but It is likely that the pauseApp() is not called.
The Midlet may finish before calling platformRequest(url) but after the call platformRequest ends, The Midlet is invoked again. So, the problem still remains.