How to handle screen orientation change when progress dialog and background thread active?

前端 未结 28 1839
轮回少年
轮回少年 2020-11-22 07:03

My program does some network activity in a background thread. Before starting, it pops up a progress dialog. The dialog is dismissed on the handler. This all works fine, exc

28条回答
  •  猫巷女王i
    2020-11-22 07:56

    When you switch orientations, Android will create a new View. You're probably getting crashes because your background thread is trying to change the state on the old one. (It may also be having trouble because your background thread isn't on the UI thread)

    I'd suggest making that mHandler volatile and updating it when the orientation changes.

提交回复
热议问题