When my Activity
makes a Volley
request, I show a dialog with a dialog fragment. And in the response handler, which is a non-static inner class of the Activity
, I dismiss the dialog fragment with:
@Override
public void onResponse(String response) {
MyActivity.this.takeAwayTheDialog();
}
Things work fine unless I rotate the device. If the response comes back after the orientation change completes, MyActivity.this
has already been destroyed.
Possible solutions include:
- Cancel the request before the orientation change
- Use a separate retained fragment to handle the network request
But they do not look satisfactory. I'd like to have a solution that allows the system to handle the orientation for me so that the activity is recreated and the correct resources are loaded. Can anyone comment on the two solutions above or give other suggestions? Thx.