android how to handle key events in async task
i am using async task while retrieving data from server,everything is working fine but when i press the back key to navigate to previous activity it throws nullpointer exception
i used KeyDow开发者_运维知识库n()
and KeyUp()
to handle the key events
Please help me
When you press the back button, your activity will finish. You should cancel your AsyncTask, before allowing this to happen. A suitable place to do so is in the OnDestroy method of your activity.
If you don't do that, you will leave a loose thread that will try to access your already destroyed activity, when the background operation finishes. This will most probably cause an exception.
精彩评论