Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert Dialog in android

Tags:

android

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?

like image 676
nila Avatar asked Nov 04 '22 08:11

nila


1 Answers

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/

like image 84
baradas Avatar answered Nov 11 '22 10:11

baradas