Background task, progress dialog, orientation change - is there any 100% working solution?

后端 未结 8 2125
半阙折子戏
半阙折子戏 2020-11-22 06:37

I download some data from internet in background thread (I use AsyncTask) and display a progress dialog while downloading. Orientation changes, Activity is rest

8条回答
  •  感情败类
    2020-11-22 07:24

    This is my solution: https://github.com/Gotchamoh/Android-AsyncTask-ProgressDialog

    Basically the steps are:

    1. I use onSaveInstanceState to save the task if it is still processing.
    2. In onCreate I get the task if it was saved.
    3. In onPause I discard the ProgressDialog if it is shown.
    4. In onResume I show the ProgressDialog if the task is still processing.

提交回复
热议问题