I have a problem that causes me some problems when a user (or another app, like the phone-application) pushes my application to the background.
My application does following:
- A User can enter some information that is supposed to be pushed to a server.
- When the user clicks "Send" i open a managed ProgressDialog and start an AsyncTask that performs the server communication.
- When server communication is complete the AsyncTask reports back to my Activity where i perform a dismissDialog().
- Directly after dismissDialog(), I will show another managed dialog using showDialog() that will inform the user about whether the submission was ok or if it failed.
This all works perfectly without any issues; however, when a call happens to come while the AsyncTask is running I get (seemingly random) one of these results:
- The activity holding the managed dialog is dismissed completely and the previous view from the stack is presented when I come back.
- The activity holding the managed dialog is still on screen, but it is grayed out without showing a dialog. The only way to fix this is to rotate the phone at which point it shows the "Submission sent"-dialog exactly the way it should and everything is ok after that.
All this happens without any warning messages so I get absolutely no clues as to why Android is behaving this way.
I know a way around this and that is to cancel the AsyncTask (so no dialogs are shown at the end). However, in this very use-case the requirements are that the app has to try to complete the server transaction so that there is as little confusion as possible (i.e. the user wondering if it was really sent or not).
Has anybody else had this issue and knows a way around?