/* List of activities with focus. */
public static List<EmacsActivity> focusedActivities;
+ /* The last activity to have been focused. */
+ public static EmacsActivity lastFocusedActivity;
+
/* The currently focused window. */
public static EmacsWindow focusedWindow;
manager.removeWindowConsumer (this, isMultitask || isFinishing ());
focusedActivities.remove (this);
invalidateFocus ();
+
+ /* Remove this activity from the static field, lest it leak. */
+ if (lastFocusedActivity == this)
+ lastFocusedActivity = null;
+
super.onDestroy ();
}
onWindowFocusChanged (boolean isFocused)
{
if (isFocused && !focusedActivities.contains (this))
- focusedActivities.add (this);
+ {
+ focusedActivities.add (this);
+ lastFocusedActivity = this;
+ }
else
focusedActivities.remove (this);
AlertDialog dialog;
if (EmacsActivity.focusedActivities.isEmpty ())
- return false;
+ {
+ /* If focusedActivities is empty then this dialog may have
+ been displayed immediately after a popup dialog is
+ dismissed. */
+
+ activity = EmacsActivity.lastFocusedActivity;
+
+ if (activity == null)
+ return false;
+ }
+ else
+ activity = EmacsActivity.focusedActivities.get (0);
- activity = EmacsActivity.focusedActivities.get (0);
dialog = dismissDialog = toAlertDialog (activity);
- dismissDialog.show ();
+
+ try
+ {
+ dismissDialog.show ();
+ }
+ catch (Exception exception)
+ {
+ /* This can happen when the system decides Emacs is not in the
+ foreground any longer. */
+ return false;
+ }
/* If there are less than four buttons, then they must be
individually enabled or disabled after the dialog is