Skip to content

android_alarm_manager no longer works in background #47406

@Hixie

Description

@Hixie
  1. flutter create -a java test_bg
  2. cd test_bg
  3. add android_alarm_manager: any to pubspec.yaml
  4. add to android/app/src/main/AndroidManifest.xml the stuff mentioned on https://pub.dev/packages/android_alarm_manager
  5. delete test/widget_test.dart
  6. update lib/main.dart as follows:
import 'dart:io';
import 'dart:isolate';
import 'package:android_alarm_manager/android_alarm_manager.dart';
import 'package:flutter/material.dart';

void callback() {
  final DateTime now = DateTime.now();
  final int isolateId = Isolate.current.hashCode;
  print("[$now] Hello, world! isolate=$isolateId function='$callback'");
}

Future<void> main() async {
  runApp(MaterialApp(home: Material(child: Center(child: OutlineButton(child: Text('QUIT'), onPressed: () => exit(0))))));
  await AndroidAlarmManager.initialize();
  await AndroidAlarmManager.periodic(const Duration(minutes: 1), 0, callback);
}
  1. flutter run
  2. Press the QUIT button, or, once the app is running, press Q at the console.
  3. flutter logs
  4. Wait approximately one minute.

Expected results: A Hello world! message with various information like the isolate ID, the time, and some representation of the callback, something like that:

I/flutter (18608): [2019-12-18 20:48:51.063338] Hello, world! isolate=704844194 function='Closure: () => void from Function 'callback': static.'

Actual results:

E/FlutterBackgroundExecutor(17500): Fatal: failed to find callback

Metadata

Metadata

Assignees

Labels

c: regressionIt was better in the past than it is nowcustomer: productp: android_alarm_managerThe Android background execution pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions