开发者

How to handle feedback from background threads if the user uses the back button?

I have the following problem:

I have an Activity where a user can start a web search showing a new activity to show a progress bar until the results are shown. Now the user can either wait for the results or maybe think about the search parameters, hit the back button and triggering a new search. The search is running in an Async Task and therefor still running if the user hits back. At the moment the thread finishes it calls some methods on the old activity ca开发者_如何学Cusing the activity to show a dialog.

This causes the system to crash because the dialog tries to show itself with a reference to an activity that is not longer present on the screen.

How can I achieve a dialog that is only shown if the activity is still active?


Call isFinishing() on your activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜