I have an application that depends on connection It has many Activities.I need to display a progress re-connection dialog whenever connection goes down and keep It till connection get back or user dismiss regardless the running Activity. I made this method which intercept the connection failure event In the BaseActivity which Is the parent of all my Activities:
public void xmppConnectionClosed() {
connectionError = true;
onScreenActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
initiateReconnectionDialog(onScreenActivity); //onScreenActivity is singlton represent the current activity
reconnectionDialog.setMessage(onScreenActivity
.getString(R.string.reconnectionDialogReconnecting));
reconnectionDialog
.setStatus(ReconnectionStatus.RECONNECTING);
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
reconnectionDialog.show();
}
});
}
Its onCreate
protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (connectionError) {
initiateReconnectionDialog(this);
reconnectionDialog.show();
}
}
the Issue now is that If I have Activity A start Activity B when I rotate the device the the onCreate of activity A is called and if I tried to show the dialog it throws an exception that It is not the foreground activity.
Any Ideas how to handle this situation?
This sounds like a Dialog that would have to be brought up from a background service. This has to be the case because you don’t care if the activity is running. The activity would have to start the service and would run in the background.