Displaying Progress Dialog At The Start Of A Gps Application
Solution 1:
I assume that the real problem you have is that you don't know when you will actually get a valid position, in that case displaying a progress bar would be difficult to do since there is no way for you to determine how far along are you.
I would recommend that you show a message the user that says "Acquiring GPS Position" and possibly have some type of animation with a GPS satellite spinning, a "signal" traveling between a GPS satellite and a GPS receiver, or a flashing GPS icon indicating that you're acquiring a GPS signal (but make it more pleasant to look at):
So in your GUI thread you will render the animation and you will simultaneously run another thread that will acquire the GPS signal. When you acquire the GPS signal you will terminate the rendering:
To start the new thread you do this:
classGPSPositionGetterextendsRunnable
{
private LocationManager _locationManager;
GPSPositionGetter(LocationManager locationManager)
publicrun()
{
_locationManager.requestLocationUpdates(...);
}
}
Threadt=newThread(newGPSPositionGetter(locationManager));
t.start();
In your GUI thread:
while(!positionAcquired)
{
renderAnimation();
}
Inside the callback method you do:
publiconLocationChanged(Location location)
{
if(IsValid(location))
{
positionAcquired = true;
}
}
Note that you should declare positionAcquired
as a volatile
in order to ensure visibility and to prevent it from being cashed in a thread's local memory.
P.S. the code is just to give you a rough idea of what to do; there are other more elegant solutions (such as using an ExecutorService
), but the general approach should not be much different.
Post a Comment for "Displaying Progress Dialog At The Start Of A Gps Application"