summaryrefslogtreecommitdiff
path: root/java/org/gnu/emacs/EmacsWindowManager.java
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2024-06-27 11:06:59 +0800
committerPo Lu <luangruo@yahoo.com>2024-06-27 11:07:38 +0800
commit860840621a1ebe2e4f17ba8ae78d441ea75650b2 (patch)
treece491e28fbd0ec6867b9669f77e92c151e8f28c7 /java/org/gnu/emacs/EmacsWindowManager.java
parentd5c6eb1f9646781cf103124fb7e88d1fa1cf2473 (diff)
Prevent crashes and related issues if initial activity is destroyed on Android
* java/org/gnu/emacs/EmacsWindow.java (EmacsWindow) <initialWindowCreated>: New variable. (EmacsWindow): If the initial frame has not yet been created, set attachmentToken to -1. * java/org/gnu/emacs/EmacsWindowManager.java (registerWindow): When the window's attachment token is -1 (i.e., it is the default window), start EmacsActivity rather than EmacsMultitaskActivity. Catch exceptions around startActivity.
Diffstat (limited to 'java/org/gnu/emacs/EmacsWindowManager.java')
-rw-r--r--java/org/gnu/emacs/EmacsWindowManager.java43
1 files changed, 36 insertions, 7 deletions
diff --git a/java/org/gnu/emacs/EmacsWindowManager.java b/java/org/gnu/emacs/EmacsWindowManager.java
index 03487e853fb..e4bd995f15a 100644
--- a/java/org/gnu/emacs/EmacsWindowManager.java
+++ b/java/org/gnu/emacs/EmacsWindowManager.java
@@ -174,6 +174,27 @@ public final class EmacsWindowManager
}
}
+ /* Do not create a multitasking activity for the initial frame,
+ but arrange to start EmacsActivity. */
+ if (window.attachmentToken == -1)
+ {
+ intent = new Intent (EmacsService.SERVICE,
+ EmacsActivity.class);
+ intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ try
+ {
+ EmacsService.SERVICE.startActivity (intent);
+ }
+ catch (Exception e)
+ {
+ Log.w (TAG, "an activity could not be started on behalf"
+ + " of the mapped default window " + window.handle);
+ }
+
+ return;
+ }
+
intent = new Intent (EmacsService.SERVICE,
EmacsMultitaskActivity.class);
@@ -205,14 +226,22 @@ public final class EmacsWindowManager
window.attachmentToken = token;
intent.putExtra (ACTIVITY_TOKEN, token);
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
- EmacsService.SERVICE.startActivity (intent);
- else
+ try
+ {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
+ EmacsService.SERVICE.startActivity (intent);
+ else
+ {
+ /* Specify the desired window size. */
+ options = ActivityOptions.makeBasic ();
+ options.setLaunchBounds (window.getGeometry ());
+ EmacsService.SERVICE.startActivity (intent, options.toBundle ());
+ }
+ }
+ catch (Exception e)
{
- /* Specify the desired window size. */
- options = ActivityOptions.makeBasic ();
- options.setLaunchBounds (window.getGeometry ());
- EmacsService.SERVICE.startActivity (intent, options.toBundle ());
+ Log.w (TAG, "an activity could not be started on behalf"
+ + " of a mapped window, " + window.handle);
}
pruneWindows ();