By: Fazal in J2ME Tutorials on 2007年09月22日 [フレーム]
This article describes using the getPosition() method to get the GPS position in the background. I call this method from a separate thread like documentation recomends, so I can show a 'Cancel' button in the display in case I want to cancel the GPS request. The thing is that I don't know how to make getPosition() function to stop requesting. I want getPosition() to stop executing when I push 'Cancel' button. How do I do that? I'm sure there is a way, because the built-in app to get GPS position stops when I cancel.
If this is your problem then here are ways to do it.
The developer guide (p 489) says that closing the PositionConnection (from another thread) will cause the call to unblock. I have not done this in a while and don't have my code handy but if this doesn't work someone will speak up. At any rate, if you make the Cancel commandAction event close the PositionConnection, then that should do it.
Other strategies:
You could always make "cancel" do nothing except return back to your main screen, and allow the connection attempt to continue in the background. There are many ways to code this, but the bottom line is that if you think a position may be needed a short time later, or a relatively recent position will suffice, you could let the connection attempt complete in the background, and if it completes successfully, store the result.
If you think the user might attempt a position again a short time later, this would be a great strategy because maybe they just didn't wait long enough. You can silently continue to try to get a connection in the background. If you are successful you can decide whether or not to keep the receiver "hot" by making additional requests, until the user tries again or you stop after a while to conserve battery. Or when you get the fix you can notify the user that it is available. If you don't get the fix, no biggie, the user will simply try again. If you are still trying to get the fix when the user tries again, you should be able to cancel the current fix by closing the PositionConnection and then reopening it. Again, the idea here is to separate UI activity from location activity and to provide an event communication mechanism between the two. There are many on this list who can offer something more precise.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in J2ME )
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Adding your own Application icon for your J2ME application (jar file)
Client Server in J2ME (Socket Programming sample)
GUI components and menu based J2ME Applications.
Code sample to Send SMS from a J2ME application.
Datagrams in J2ME (UDP Programming sample)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
RMSCookieConnector - Using Cookies in J2ME
Using HTTP vs UDP vs Socket in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
Latest Articles (in J2ME)
GUI components and menu based J2ME Applications.
Code sample to Send SMS from a J2ME application.
Adding your own Application icon for your J2ME application (jar file)
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Datagrams in J2ME (UDP Programming sample)
Client Server in J2ME (Socket Programming sample)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
Using HTTP vs UDP vs Socket in J2ME
RMSCookieConnector - Using Cookies in J2ME
POST UTF-8 encoded data to the server in J2ME
Using alerts and tickers in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
GUI components and menu based J2ME Applications.
Code sample to Send SMS from a J2ME application.
Adding your own Application icon for your J2ME application (jar file)
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Datagrams in J2ME (UDP Programming sample)
Client Server in J2ME (Socket Programming sample)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
Using HTTP vs UDP vs Socket in J2ME
RMSCookieConnector - Using Cookies in J2ME
POST UTF-8 encoded data to the server in J2ME
Using alerts and tickers in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate