Skip to content

Commit

Permalink
[android_alarm_manager] Fixed issue where callback lookup was failing…
Browse files Browse the repository at this point in the history
… in the background (flutter#2453)

If callback lookup was attempted before Flutter was initialized, the
callback cache would not yet be populated resulting in a failed callback
lookup.
  • Loading branch information
bkonyi authored and Egor committed Nov 20, 2020
1 parent 8c96c23 commit 9c5b453
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/android_alarm_manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.5+3

* Fixed issue where callback lookup would fail while running in the background.

## 0.4.5+2

* Remove the deprecated `author:` field from pubspec.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,22 @@ public void startBackgroundIsolate(Context context, long callbackHandle) {
return;
}

FlutterCallbackInformation flutterCallback =
FlutterCallbackInformation.lookupCallbackInformation(callbackHandle);
if (flutterCallback == null) {
Log.e(TAG, "Fatal: failed to find callback");
return;
}
Log.i(TAG, "Starting AlarmService...");
String appBundlePath = FlutterMain.findAppBundlePath(context);
AssetManager assets = context.getAssets();
if (appBundlePath != null && !isRunning()) {
backgroundFlutterEngine = new FlutterEngine(context);

// We need to create an instance of `FlutterEngine` before looking up the
// callback. If we don't, the callback cache won't be initialized and the
// lookup will fail.
FlutterCallbackInformation flutterCallback =
FlutterCallbackInformation.lookupCallbackInformation(callbackHandle);
if (flutterCallback == null) {
Log.e(TAG, "Fatal: failed to find callback");
return;
}

DartExecutor executor = backgroundFlutterEngine.getDartExecutor();
initializeMethodChannel(executor);
DartCallback dartCallback = new DartCallback(assets, appBundlePath, flutterCallback);
Expand Down
2 changes: 1 addition & 1 deletion packages/android_alarm_manager/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: android_alarm_manager
description: Flutter plugin for accessing the Android AlarmManager service, and
running Dart code in the background when alarms fire.
version: 0.4.5+2
version: 0.4.5+3
homepage: https://github.com/flutter/plugins/tree/master/packages/android_alarm_manager

dependencies:
Expand Down

0 comments on commit 9c5b453

Please sign in to comment.