How to implement a ProgressDialog while Activity requests a SoapObject from a Web Service?

后端 未结 4 1805
既然无缘
既然无缘 2021-01-21 09:06

I know that ProgressDialog with Threads questions have been asked many times but none of the solutions seem to work for my project. Basically what I want to do is this: 1) when

4条回答
  •  孤独总比滥情好
    2021-01-21 10:03

    As others already wrote, AsyncTask is the way to proceed.

    BUT: AsyncTask and Threads have some pitfalls for UI elements:

    If you change the phone orientation and did not set android:configChanges="keyboardHidden|orientation" for your Activity (means you have to handle onConfigChange by yourself) in the Manifest.xml, an orientation change will destroy and recreate your Activity and ContentView and also disconnect the ProgressDialog from the visible window (it's connected to the old one). Android is NOT going to kill your Thread or AsyncTask. It also won't kill it if the Activity is destroyed. Those background Task continue until they are done.

    Trying to dismiss() your previsously created ProgressDialog throws an exception after the ContentView got destroyed, as it is not part of your window anymore. try/catch a LOT in situations doing something detached (async) work. Everything you possibly rely on just could have vanished or replaced by something different when onPostExecute() gets called again. Eventually think about registering every ASyncTask you start in some Array in your Activity and try to cancel() them at your Activity.onDestroy().

提交回复
热议问题