flutter_foreground_task's stopWithTask option (9.2 to 11.0) does not wait for the task to be removed: it registers activity lifecycle callbacks and stops the service on the first onActivityPaused with no resumed activity. So the "MeshCore background" service stopped every time the app went to the background or the screen turned off. Android then cached and froze the process, the Bluetooth link dropped and the low-memory killer ended the app a few hours later. Usage stats on a Pixel show FOREGROUND_SERVICE_STOP in the same second as every ACTIVITY_STOPPED. Drop the option. android:stopWithTask="true" in the manifest still stops the service when the app is swiped away, which is what the option was meant to do.
16 lines
647 B
Dart
16 lines
647 B
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:meshcore_open/services/background_service.dart';
|
|
|
|
void main() {
|
|
test('the foreground service does not stop when the app goes to the '
|
|
'background', () {
|
|
// flutter_foreground_task's stopWithTask option stops the service on the
|
|
// first activity pause, not on task removal. Swipe-away is handled by
|
|
// android:stopWithTask in the manifest instead.
|
|
final options = BackgroundService.taskOptions;
|
|
expect(options.stopWithTask, isNull);
|
|
expect(options.toJson().containsKey('stopWithTask'), isFalse);
|
|
expect(options.allowAutoRestart, isFalse);
|
|
});
|
|
}
|