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

后端 未结 8 2226
半阙折子戏
半阙折子戏 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:16

    While Mark's (CommonsWare) answer does indeed work for orientation changes, it fails if the Activity is destroyed directly (like in the case of a phone call).

    You can handle the orientation changes AND the rare destroyed Activity events by using an Application object to reference your ASyncTask.

    There's an excellent explanation of the problem and the solution here:

    Credit goes completely to Ryan for figuring this one out.

提交回复
热议问题