5

In my application I used an alert dialog box to show 'connection error' message if API call fails. API calls are written with in an AsyncTask. While API is called 'loading' dialog is shown, onPostExecute I will dismiss this 'loading' dilaogue , after that if the API call fails I will show the 'connection error' message.

My problem is while the 'loading' dialog is shown if I press the home button and when I come back to the app, app is in freezed state.

I think the problem is with the 'Connection Error' AlertDailog box,if I remove alertDailog.show,we will not get this issue.

How to solve this?

2
  • have you testing it on device? Commented Dec 27, 2011 at 6:17
  • In device and emulator,I am getting this issue Commented Dec 27, 2011 at 6:19

1 Answer 1

2

When the home button is pressed you can choose to cancel the Async task in the onPause() method of the Activity and also close the loading dialog.

When activity resumes (app is brought to foreground), restart your AsyncTask.

This is a good read to your question : http://blog.doityourselfandroid.com/2010/11/14/handling-progress-dialogs-and-screen-orientation-changes/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.