Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android show progress dialog while waiting for location

I'm developing location based app using this example: http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/

But when I turn on phone, the location isn't available right on that moment. So I would like to show progress dialog while waiting for the location. Wanna do this in the background using AsyncTask.

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

like image 500
Karlis Avatar asked Jul 16 '13 08:07

Karlis


People also ask

How to create a custom Progress dialog in Android?

Using the Custom Progress Dialog To use it, declare the class CustomProgressDialog at the beginning of your Activity: class MainActivity : AppCompatActivity() { private val progressDialog by lazy { CustomProgressDialog(this) } override fun onCreate(savedInstanceState: Bundle?) { super.

What is ProgressDialog in Android?

ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar , which can be embedded in your app's UI. Alternatively, you can use a notification to inform the user of the task's progress.

What is indeterminate progress bar Android?

Indeterminate mode is the default for progress bar and shows a cyclic animation without a specific amount of progress indicated. The following example shows an indeterminate progress bar: <ProgressBar android:id="@+id/indeterminateBar" android:layout_width="wrap_content" android:layout_height="wrap_content" />


1 Answers

There is no need of AsyncTask because Location service already running in different process, Just implement the LocationListener and register it on resume method, and in onCreateActivity check if location is null, the show the ProgressDialog, and in onLocationChanged() set the location and close the ProgressDialog

like image 102
Kapil Vats Avatar answered Nov 14 '22 23:11

Kapil Vats