Show Android progress dialog while waiting for location

I am developing a location application using this example: http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/

But when I turn on the phone, at that moment this place is inaccessible. Therefore, I want to show a dialogue of progress in anticipation of a location. Want to do this in the background using AsyncTask.

Can you give any ideas how and where to do it?

+4
source share
4 answers

AsyncTask is not needed because the location service is already running in another process. Just implement the LocationListener and register it with the renew method, and in onCreateActivity check if the location is null, show ProgressDialog and in onLocationChanged() set the location and close the ProgressDialog

+3
source

Put your ProgressDialog in onPreExecute, sample code below:

 private ProgressDialog progressdialog; @Override protected void onPreExecute(){ super.onPreExecute(); progressdialog = new ProgressDialog(yourContext); progressdialog.setMessage("Loading..."); progressdialog.show(); } @Override protected void onPostExecute(){ super.onPostExecute(); progressdialog.dismiss(); } 
+2
source

I wrote a solution for using ProgressDialog in AsyncTask in the following section:

Displaying a ProgressDialog while waiting for a merged stream

+1
source

Implement the locationListner interface and start the wait dialog, override the onlocation change method and just cancel the dialog, the best.

public class MainActivity extends Activity implements LocationListener {

 ProgressDialog dialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //-------------------- Start your GPS Reading ------------------ // dialog = new ProgressDialog(this); dialog.setMessage("Please wait!"); dialog.show(); } @Override public void onLocationChanged(Location arg0) { dialog.dismiss(); } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } 
+1
source

Source: https://habr.com/ru/post/1491598/


All Articles