Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit de56da5

Browse files
authored
[android_alarm_manager] Fixed issue where callback lookup was failing in the background (#2453)
If callback lookup was attempted before Flutter was initialized, the callback cache would not yet be populated resulting in a failed callback lookup.
1 parent 0302867 commit de56da5

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

packages/android_alarm_manager/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.5+3
2+
3+
* Fixed issue where callback lookup would fail while running in the background.
4+
15
## 0.4.5+2
26

37
* Remove the deprecated `author:` field from pubspec.yaml

packages/android_alarm_manager/android/src/main/java/io/flutter/plugins/androidalarmmanager/FlutterBackgroundExecutor.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,22 @@ public void startBackgroundIsolate(Context context, long callbackHandle) {
151151
return;
152152
}
153153

154-
FlutterCallbackInformation flutterCallback =
155-
FlutterCallbackInformation.lookupCallbackInformation(callbackHandle);
156-
if (flutterCallback == null) {
157-
Log.e(TAG, "Fatal: failed to find callback");
158-
return;
159-
}
160154
Log.i(TAG, "Starting AlarmService...");
161155
String appBundlePath = FlutterMain.findAppBundlePath(context);
162156
AssetManager assets = context.getAssets();
163157
if (appBundlePath != null && !isRunning()) {
164158
backgroundFlutterEngine = new FlutterEngine(context);
159+
160+
// We need to create an instance of `FlutterEngine` before looking up the
161+
// callback. If we don't, the callback cache won't be initialized and the
162+
// lookup will fail.
163+
FlutterCallbackInformation flutterCallback =
164+
FlutterCallbackInformation.lookupCallbackInformation(callbackHandle);
165+
if (flutterCallback == null) {
166+
Log.e(TAG, "Fatal: failed to find callback");
167+
return;
168+
}
169+
165170
DartExecutor executor = backgroundFlutterEngine.getDartExecutor();
166171
initializeMethodChannel(executor);
167172
DartCallback dartCallback = new DartCallback(assets, appBundlePath, flutterCallback);

packages/android_alarm_manager/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: android_alarm_manager
22
description: Flutter plugin for accessing the Android AlarmManager service, and
33
running Dart code in the background when alarms fire.
4-
version: 0.4.5+2
4+
version: 0.4.5+3
55
homepage: https://github.com/flutter/plugins/tree/master/packages/android_alarm_manager
66

77
dependencies:

0 commit comments

Comments
 (0)