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?
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.
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.
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" />
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With