diff options
| author | Po Lu | 2024-03-25 15:42:23 +0800 |
|---|---|---|
| committer | Po Lu | 2024-03-25 15:42:23 +0800 |
| commit | ba96c4ec56a9978fce155c0af34a0412aee817b2 (patch) | |
| tree | b3371bd73fe7c423fd9e183ef885245e819dcd8e /java/org | |
| parent | c5de73a95a6ecefe46fe1ac07da8e83032be7f5b (diff) | |
| download | emacs-ba96c4ec56a9978fce155c0af34a0412aee817b2.tar.gz emacs-ba96c4ec56a9978fce155c0af34a0412aee817b2.zip | |
Port restart-emacs to Android 4.3 and earlier
* java/org/gnu/emacs/EmacsService.java (restartEmacs): Run Emacs
from an alarm if required.
Diffstat (limited to 'java/org')
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index 07bfb525be9..4e863c750d3 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -46,9 +46,11 @@ import android.view.KeyEvent; | |||
| 46 | import android.view.inputmethod.CursorAnchorInfo; | 46 | import android.view.inputmethod.CursorAnchorInfo; |
| 47 | import android.view.inputmethod.ExtractedText; | 47 | import android.view.inputmethod.ExtractedText; |
| 48 | 48 | ||
| 49 | import android.app.AlarmManager; | ||
| 49 | import android.app.Notification; | 50 | import android.app.Notification; |
| 50 | import android.app.NotificationManager; | ||
| 51 | import android.app.NotificationChannel; | 51 | import android.app.NotificationChannel; |
| 52 | import android.app.NotificationManager; | ||
| 53 | import android.app.PendingIntent; | ||
| 52 | import android.app.Service; | 54 | import android.app.Service; |
| 53 | 55 | ||
| 54 | import android.content.ClipboardManager; | 56 | import android.content.ClipboardManager; |
| @@ -724,11 +726,29 @@ public final class EmacsService extends Service | |||
| 724 | restartEmacs () | 726 | restartEmacs () |
| 725 | { | 727 | { |
| 726 | Intent intent; | 728 | Intent intent; |
| 729 | PendingIntent pending; | ||
| 730 | AlarmManager manager; | ||
| 727 | 731 | ||
| 728 | intent = new Intent (this, EmacsActivity.class); | 732 | intent = new Intent (this, EmacsActivity.class); |
| 729 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK | 733 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK |
| 730 | | Intent.FLAG_ACTIVITY_CLEAR_TASK); | 734 | | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 731 | startActivity (intent); | 735 | |
| 736 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) | ||
| 737 | startActivity (intent); | ||
| 738 | else | ||
| 739 | { | ||
| 740 | /* Experimentation has established that Android 4.3 and earlier | ||
| 741 | versions do not attempt to recreate a process when it crashes | ||
| 742 | immediately after requesting that an intent for itself be | ||
| 743 | started. Schedule an intent to start some time after Emacs | ||
| 744 | exits instead. */ | ||
| 745 | |||
| 746 | pending = PendingIntent.getActivity (this, 0, intent, 0); | ||
| 747 | manager = (AlarmManager) getSystemService (Context.ALARM_SERVICE); | ||
| 748 | manager.set (AlarmManager.RTC, System.currentTimeMillis () + 100, | ||
| 749 | pending); | ||
| 750 | } | ||
| 751 | |||
| 732 | System.exit (0); | 752 | System.exit (0); |
| 733 | } | 753 | } |
| 734 | 754 | ||