[android_alarm_manager] Move method channel usage to the platform main thread (#1641)
Fixes https://github.com/flutter/flutter/issues/32976
diff --git a/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java b/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java
index 6c13f79..2851846 100644
--- a/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java
+++ b/packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/AlarmService.java
@@ -9,6 +9,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.os.Handler;
import android.util.Log;
import androidx.core.app.JobIntentService;
import io.flutter.plugin.common.MethodChannel;
@@ -421,7 +422,7 @@
* callbacks have been executed.
*/
@Override
- protected void onHandleWork(Intent intent) {
+ protected void onHandleWork(final Intent intent) {
// If we're in the middle of processing queued alarms, add the incoming
// intent to the queue and return.
synchronized (sAlarmQueue) {
@@ -434,6 +435,13 @@
// There were no pre-existing callback requests. Execute the callback
// specified by the incoming intent.
- executeDartCallbackInBackgroundIsolate(intent);
+ new Handler(getMainLooper())
+ .post(
+ new Runnable() {
+ @Override
+ public void run() {
+ executeDartCallbackInBackgroundIsolate(intent);
+ }
+ });
}
}