transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
645 stars 239 forks source link

Could not make the context current - EGL Error: EGL_BAD_ACCESS (12290) #64

Closed darioxtx closed 5 years ago

darioxtx commented 5 years ago

Your Environment

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3) • Android SDK at C:\Users\dstai\AppData\Local\Android\sdk • Android NDK location not configured (optional; useful for native profiling support) • Platform android-28, build-tools 28.0.3 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01) X Android license status unknown. Try re-installing or updating your Android SDK Manager. See https://developer.android.com/studio/#downloads or visit https://flutter.io/setup/#android-setup for detailed instructions.

[√] Android Studio (version 3.4) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin version 35.3.1 • Dart plugin version 183.6270 • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] Connected device (1 available) • motorola one • ZY32398QP7 • android-arm64 • Android 9 (API 28)

Expected Behavior

App must not crash

Actual Behavior

App crash in some state that flutter create new app instance but leave old instance running. that cause lot of bad behavior. for example if I was subscribed for notifications, that subscription executes twice and more.

Steps to Reproduce

  1. start app
  2. enable geo location tracking.
  3. after app loads close app with android back button
  4. open app from background

Debug logs

Logs ``` D/TSLocationManager(25690): [c.t.l.a.BackgroundGeolocation c] D/TSLocationManager(25690): 🔴 Cleared callbacks D/TSLocationManager(25690): [c.t.l.a.BackgroundGeolocation isMainActivityActive] NO D/TSLocationManager(25690): [c.t.l.g.TSGeofenceManager b] D/TSLocationManager(25690): 🔴 Stop monitoring geofences I/TSLocationManager(25690): [c.t.l.g.TSGeofenceManager stopMonitoringSignificantLocationChanges] I/TSLocationManager(25690): 🔴 Stop monitoring significant location changes D/TSLocationManager(25690): [c.t.l.g.TSGeofenceManager stopMonitoringStationaryRegion] D/TSLocationManager(25690): 🔴 Stop monitoring stationary region I/TSLocationManager(25690): [c.t.l.s.ActivityRecognitionService b] I/TSLocationManager(25690): 🔴 Stop motion-activity updates I/TSLocationManager(25690): [c.t.l.service.HeartbeatService a] I/TSLocationManager(25690): 🔴 Stop heartbeat D/TSLocationManager(25690): [c.t.l.http.HttpService stopMonitoringConnectivityChanges] D/TSLocationManager(25690): 🔴 Stop monitoring connectivity changes D/TSLocationManager(25690): [c.t.locationmanager.device.a d] D/TSLocationManager(25690): 🔴 Stop monitoring powersave changes I/TSLocationManager(25690): [c.t.l.a.BackgroundGeolocation f] I/TSLocationManager(25690): 🔴 Stop monitoring location-provider changes I/TSLocationManager(25690): [c.t.l.s.TSScheduleManager stop] I/TSLocationManager(25690): 🔴 Scheduler OFF I/TSLocationManager(25690): [c.t.l.a.BackgroundGeolocation onActivityDestroy] I/TSLocationManager(25690): ╔═════════════════════════════════════════════ I/TSLocationManager(25690): ║ MainActivity was destroyed I/TSLocationManager(25690): ╠═════════════════════════════════════════════ I/TSLocationManager(25690): ╟─ stopOnTerminate: true I/TSLocationManager(25690): ╟─ enabled: false D/TSLocationManager(25690): [c.t.l.service.TrackingService onDestroy] D/TSLocationManager(25690): 🔴 TrackingService destroyed D/TSLocationManager(25690): [c.t.l.s.ActivityRecognitionService onDestroy] D/TSLocationManager(25690): 🔴 ActivityRecognitionService destroyed W/ActivityThread(25690): handleWindowVisibility: no activity for token android.os.BinderProxy@b22cc54 E/libEGL (25690): eglMakeCurrent:1091 error 3002 (EGL_BAD_ACCESS) E/flutter (25690): [ERROR:flutter/shell/platform/android/android_context_gl.cc(217)] Could not make the context current E/flutter (25690): [ERROR:flutter/shell/platform/android/android_context_gl.cc(53)] EGL Error: EGL_BAD_ACCESS (12290) D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/location D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/motionchange D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/activitychange D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/geofenceschange D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/geofence D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/heartbeat D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/http D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/schedule D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/connectivitychange D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/enabledchange D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/providerchange D/TSLocationManager(25690): [c.t.f.b.streams.StreamHandler register] com.transistorsoft/flutter_background_geolocation/events/powersavechange D/MainActivity(25690): onStart E/libEGL (25690): eglMakeCurrent:1091 error 3002 (EGL_BAD_ACCESS) E/flutter (25690): [ERROR:flutter/shell/platform/android/android_context_gl.cc(217)] Could not make the context current E/flutter (25690): [ERROR:flutter/shell/platform/android/android_context_gl.cc(53)] EGL Error: EGL_BAD_ACCESS (12290) ```
christocracy commented 5 years ago

I cannot reproduce this.

And why do you configure the Notification smallIcon, largeIcon prefixed with @? The docs don't instruct you to do that.

largeIcon: "@drawable/ic_launcher", 
smallIcon: "@drawable/ic_stat_name",
darioxtx commented 5 years ago

Configuration fix did not help. I have singletons on my app and I think it's related. I will try create reproducible code.

christocracy commented 5 years ago

This too is curious. It should say stopOnTerminate: false, as configured to #ready.

TSLocationManager(25690): ╔═════════════════════════════════════════════
I/TSLocationManager(25690): ║ MainActivity was destroyed
I/TSLocationManager(25690): ╠═════════════════════════════════════════════
I/TSLocationManager(25690): ╟─ stopOnTerminate: true
I/TSLocationManager(25690): ╟─ enabled: false
D/TSLocationManager(25690): [c.t.l.service.TrackingService onDestroy] 
darioxtx commented 5 years ago

Running this code I am able to reproduce this issue. steps:

// Flutter code sample for material.AppBar.1

// This sample shows an [AppBar] with two simple actions. The first action
// opens a [SnackBar], while the second action navigates to a new page.

import 'package:flutter/material.dart';
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;

void main() => runApp(MyApp());

/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: MyStatelessWidget(),
    );
  }
}

final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
final SnackBar snackBar = const SnackBar(content: Text('Showing Snackbar'));

void openPage(BuildContext context) {
  Navigator.push(context, MaterialPageRoute(
    builder: (BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: const Text('Next page'),
        ),
        body: const Center(
          child: Text(
            'This is the next page',
            style: TextStyle(fontSize: 24),
          ),
        ),
      );
    },
  ));
}

/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
  final _locationService = LocationService();
  MyStatelessWidget({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: scaffoldKey,
      appBar: AppBar(
        title: const Text('AppBar Demo'),
        actions: <Widget>[
          IconButton(
            icon: const Icon(Icons.add_alert),
            tooltip: 'Show Snackbar',
            onPressed: () {
              scaffoldKey.currentState.showSnackBar(snackBar);
              _locationService.initGeoLocationManager();
            },
          ),
          IconButton(
            icon: const Icon(Icons.navigate_next),
            tooltip: 'Next page',
            onPressed: () {
              openPage(context);
            },
          ),
        ],
      ),
      body: const Center(
        child: Text(
          'This is the home page',
          style: TextStyle(fontSize: 24),
        ),
      ),
    );
  }
}

class LocationService {
  static final LocationService _singleton = new LocationService._internal();

  factory LocationService() {
    return _singleton;
  }

  LocationService._internal();

  Future<void> initGeoLocationManager() async {
    print('Initializing...');

    // Fired whenever a location is recorded
    bg.BackgroundGeolocation.onLocation((bg.Location location) async {
      print('[location] - $location');
    });

    bg.BackgroundGeolocation.ready(bg.Config(
      desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
      disableLocationAuthorizationAlert: false,
      distanceFilter: 100.0,
      heartbeatInterval: 300,
      stopOnTerminate: false,
      startOnBoot: true,
      useSignificantChangesOnly: false,
      allowIdenticalLocations: true,
      activityType: bg.Config.ACTIVITY_TYPE_OTHER,
      enableHeadless: false,
      foregroundService: true,
      logMaxDays: 1,
      maxDaysToPersist: 1,
      maxRecordsToPersist: 10,
      notification: new bg.Notification(
        channelName: "Background Location Services",
        text: "Checking your current location, for better proximity notifications",
        title: "Background Location Services",
        priority: bg.Config.NOTIFICATION_PRIORITY_DEFAULT,
        largeIcon: "drawable/ic_launcher",
        smallIcon: "drawable/ic_stat_name",

      ),
      debug: false,
      logLevel: bg.Config.LOG_LEVEL_DEBUG,
      reset: true,
      /*url: url,
      extras: {
        "Username": _globalValues.username,
        "DeviceId": _globalValues.uniqueIdentifier,
      },*/
    )).then((bg.State state) {
      if (!state.enabled) {
        ////
        // 3.  Start the plugin.
        //
        bg.BackgroundGeolocation.start();
        print('Geolocation has been started');
      }
    });
    print('Initialization done');
  }

  startTrackingLocationChanges() async {
    await initGeoLocationManager();
  }

  stopTrackingLocationChanges() async {
    await bg.BackgroundGeolocation.stop();
  }
}
darioxtx commented 5 years ago

Hi,

Did you had a chance to look at this issue?

christocracy commented 5 years ago

When I click your [bell] button, everything works.

05-30 08:20:18.808 16884 16903 I flutter : Initializing...
05-30 08:20:18.843 16884 16903 I flutter : Initialization done
05-30 08:20:18.860 16884 16884 D TSLocationManager: [c.t.l.adapter.TSConfig c] ℹ️   Persist config, dirty: [allowIdenticalLocations, debug, desiredAccuracy, distanceFilter, heartbeatInterval, logLevel, logMaxDays, maxRecordsToPersist, notification, notification.title, notification.text, notification.smallIcon, notification.largeIcon, notification.channelName, startOnBoot, stopOnTerminate]
05-30 08:20:18.918 16884 16884 D TSLocationManager: [c.t.l.a.BackgroundGeolocation ready] LocationPermission :false
05-30 08:20:18.932 16884 16903 I flutter : Geolocation has been started
05-30 08:20:18.935 16884 16884 I TSLocationManager: [c.t.locationmanager.util.b a]
05-30 08:20:18.935 16884 16884 I TSLocationManager:   🔵  LocationAuthorization: Requesting permission
05-30 08:20:21.710 16884 16884 I TSLocationManager: [c.t.locationmanager.util.b$1 onPermissionGranted]
05-30 08:20:21.710 16884 16884 I TSLocationManager:   ✅  LocationAuthorization: Permission granted
05-30 08:20:21.716 16884 16983 I TSLocationManager: - Enable: false → true, trackingMode: 1
05-30 08:20:21.740 16884 16983 I TSLocationManager: [c.t.l.g.TSGeofenceManager stopMonitoringSignificantLocationChanges]
05-30 08:20:21.740 16884 16983 I TSLocationManager:   🔴  Stop monitoring significant location changes
05-30 08:20:21.769 16884 16983 I TSLocationManager: [c.t.l.service.HeartbeatService b]
05-30 08:20:21.769 16884 16983 I TSLocationManager:   🎾  Start heartbeat (300s)
05-30 08:20:21.778 16884 16983 D TSLocationManager: [c.t.locationmanager.util.b a]
05-30 08:20:21.778 16884 16983 D TSLocationManager:   ℹ️  LocationAuthorization: Permission granted
05-30 08:20:21.784 16884 16983 I TSLocationManager: [c.t.l.service.TrackingService a]
05-30 08:20:21.784 16884 16983 I TSLocationManager:   🔵  setPace: false → false
05-30 08:20:21.789 16884 16983 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a]
05-30 08:20:21.789 16884 16983 I TSLocationManager:   🎾  Start motion-activity updates
05-30 08:20:21.794 16884 16983 I TSLocationManager: [c.t.l.g.TSGeofenceManager start]
05-30 08:20:21.794 16884 16983 I TSLocationManager:   🎾  Start monitoring geofences
05-30 08:20:21.800 16884 16983 D TSLocationManager: [c.t.l.http.HttpService startMonitoringConnectivityChanges]
05-30 08:20:21.800 16884 16983 D TSLocationManager:   🎾  Start monitoring connectivity changes
05-30 08:20:21.808 16884 16983 D TSLocationManager: [c.t.locationmanager.device.a c]
05-30 08:20:21.808 16884 16983 D TSLocationManager:   🎾  Start monitoring powersave changes
05-30 08:20:21.812 16884 16988 D TSLocationManager: [c.t.l.http.HttpService a]
05-30 08:20:21.812 16884 16988 D TSLocationManager: ╔═════════════════════════════════════════════
05-30 08:20:21.812 16884 16988 D TSLocationManager: ║ 📶  Connectivity change: connected? true
05-30 08:20:21.812 16884 16988 D TSLocationManager: ╠═════════════════════════════════════════════
05-30 08:20:21.834 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:21.847 16884 16884 D TSLocationManager: [c.t.l.s.ActivityRecognitionService a]
05-30 08:20:21.847 16884 16884 D TSLocationManager:   🚘 ️DetectedActivity [type=STILL, confidence=100]
05-30 08:20:21.862 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:21.873 16884 16884 I TSLocationManager: [c.t.l.s.LocationRequestService b]
05-30 08:20:21.873 16884 16884 I TSLocationManager:   ℹ️  Location availability: true
05-30 08:20:21.877 16884 16884 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy]
05-30 08:20:21.877 16884 16884 D TSLocationManager:   🔴  ActivityRecognitionService destroyed
05-30 08:20:21.897 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:21.913 16884 16884 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a]
05-30 08:20:21.913 16884 16884 I TSLocationManager: ╔═════════════════════════════════════════════
05-30 08:20:21.913 16884 16884 I TSLocationManager: ║ Motion Transition Result
05-30 08:20:21.913 16884 16884 I TSLocationManager: ╠═════════════════════════════════════════════
05-30 08:20:21.913 16884 16884 I TSLocationManager: ╟─ 🎾  ENTER: still
05-30 08:20:21.913 16884 16884 I TSLocationManager: ╚═════════════════════════════════════════════
05-30 08:20:22.018 16884 16884 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy]
05-30 08:20:22.018 16884 16884 D TSLocationManager:   🔴  ActivityRecognitionService destroyed
05-30 08:20:22.973 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:22.985 16884 16884 I TSLocationManager: [c.t.l.s.LocationRequestService a]
05-30 08:20:22.985 16884 16884 I TSLocationManager: ╔═════════════════════════════════════════════
05-30 08:20:22.985 16884 16884 I TSLocationManager: ║ motionchange LocationResult: 1
05-30 08:20:22.985 16884 16884 I TSLocationManager: ╠═════════════════════════════════════════════
05-30 08:20:22.985 16884 16884 I TSLocationManager: ╟─ 📍  Location[fused 45.519251,-73.616939 hAcc=15 et=+21h7m31s341ms alt=44.099998474121094 vAcc=3 sAcc=??? bAcc=??? {Bundle[mParcelledData.dataSize=52]}], age: 1092ms, time: 1559218821892
05-30 08:20:22.992 16884 16884 I TSLocationManager: [c.t.l.l.TSLocationManager onSingleLocationResult]
05-30 08:20:22.992 16884 16884 I TSLocationManager:   🔵  Acquired motionchange position, isMoving: false
05-30 08:20:22.995 16884 16884 D TSLocationManager: [c.t.l.l.TSLocationManager calculateMedianAccuracy] Median accuracy: 14.934
05-30 08:20:23.053 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:23.055 16884 16983 I TSLocationManager: [c.t.l.data.sqlite.b persist]
05-30 08:20:23.055 16884 16983 I TSLocationManager:   ✅  INSERT: 44961b44-e1ce-478f-acba-df52e176bcaa
05-30 08:20:23.061 16884 16983 D TSLocationManager: [c.t.l.data.sqlite.b a]
05-30 08:20:23.061 16884 16983 D TSLocationManager:   ℹ️  SHRINK: 10
05-30 08:20:23.072 16884 16884 D TSLocationManager: [c.t.l.g.TSGeofenceManager startMonitoringStationaryRegion]
05-30 08:20:23.072 16884 16884 D TSLocationManager:   🎾  Start monitoring stationary region (radius: 150.0 meters)
05-30 08:20:23.078 16884 16884 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a]
05-30 08:20:23.078 16884 16884 I TSLocationManager:   🎾  Start motion-activity updates
05-30 08:20:23.084  2063  2870 I GeofencerStateMachine: addGeofences called by com.example.foo
05-30 08:20:23.093  2063  3268 I GeofencerStateMachine: Use last location to update newly added Geofences.
05-30 08:20:23.096 16884 16903 I flutter : [location] - [Location {odometer: 0.0, activity: {confidence: 100, type: still}, extras: {}, event: motionchange, battery: {level: 0.96, is_charging: true}, uuid: 44961b44-e1ce-478f-acba-df52e176bcaa, coords: {altitude: 44.1, heading: -1.0, latitude: 45.5192507, accuracy: 14.9, speed: -1.0, longitude: -73.6169389}, is_moving: false, timestamp: 2019-05-30T12:20:21.892Z}]
05-30 08:20:23.097 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:23.110 16884 16884 I TSLocationManager: [c.t.l.service.TrackingService f]
05-30 08:20:23.110 16884 16884 I TSLocationManager: ╔═════════════════════════════════════════════
05-30 08:20:23.110 16884 16884 I TSLocationManager: ║ TrackingService motionchange: false
05-30 08:20:23.110 16884 16884 I TSLocationManager: ╠═════════════════════════════════════════════
05-30 08:20:23.115 16884 16884 D TSLocationManager: [c.t.l.service.TrackingService onDestroy]
05-30 08:20:23.115 16884 16884 D TSLocationManager:   🔴  TrackingService destroyed
05-30 08:20:23.163 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:23.172 16884 16884 D TSLocationManager: [c.t.l.s.ActivityRecognitionService a]
05-30 08:20:23.172 16884 16884 D TSLocationManager:   🚘 ️DetectedActivity [type=STILL, confidence=100]
05-30 08:20:23.182 16884 16884 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy]
05-30 08:20:23.182 16884 16884 D TSLocationManager:   🔴  ActivityRecognitionService destroyed
05-30 08:20:23.198 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:23.207 16884 16884 D TSLocationManager: [c.t.l.s.ActivityRecognitionService a]
05-30 08:20:23.207 16884 16884 D TSLocationManager:   🚘 ️DetectedActivity [type=STILL, confidence=100]
05-30 08:20:23.217 16884 16884 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy]
05-30 08:20:23.217 16884 16884 D TSLocationManager:   🔴  ActivityRecognitionService destroyed
05-30 08:20:23.233 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:23.243 16884 16884 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a]
05-30 08:20:23.243 16884 16884 I TSLocationManager: ╔═════════════════════════════════════════════
05-30 08:20:23.243 16884 16884 I TSLocationManager: ║ Motion Transition Result
05-30 08:20:23.243 16884 16884 I TSLocationManager: ╠═════════════════════════════════════════════
05-30 08:20:23.243 16884 16884 I TSLocationManager: ╟─ 🎾  ENTER: still
05-30 08:20:23.243 16884 16884 I TSLocationManager: ╚═════════════════════════════════════════════
05-30 08:20:23.259 16884 16884 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher
05-30 08:20:23.269 16884 16884 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a]
05-30 08:20:23.269 16884 16884 I TSLocationManager: ╔═════════════════════════════════════════════
05-30 08:20:23.269 16884 16884 I TSLocationManager: ║ Motion Transition Result
05-30 08:20:23.269 16884 16884 I TSLocationManager: ╠═════════════════════════════════════════════
05-30 08:20:23.269 16884 16884 I TSLocationManager: ╟─ 🎾  ENTER: still
05-30 08:20:23.269 16884 16884 I TSLocationManager: ╚═════════════════════════════════════════════
05-30 08:20:23.374 16884 16884 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy]
05-30 08:20:23.374 16884 16884 D TSLocationManager:   🔴  ActivityRecognitionService destroyed
christocracy commented 5 years ago

Btw, you don't want to hide the call to #ready behind some UI action, such as clicking a button or navigating to some view.

#ready should be called each time the app boots, regardless of anything. Your app logic / UI will choose to #start / #stop.

christocracy commented 5 years ago

And clicking [back] to terminate, shows:

05-30 08:28:59.576 17366 17366 D TSLocationManager: [c.t.l.a.BackgroundGeolocation c]
05-30 08:28:59.576 17366 17366 D TSLocationManager:   🔴  Cleared callbacks
05-30 08:28:59.582 17366 17366 I TSLocationManager: [c.t.l.a.BackgroundGeolocation onActivityDestroy]
05-30 08:28:59.582 17366 17366 I TSLocationManager: ╔═════════════════════════════════════════════
05-30 08:28:59.582 17366 17366 I TSLocationManager: ║ MainActivity was destroyed
05-30 08:28:59.582 17366 17366 I TSLocationManager: ╠═════════════════════════════════════════════
05-30 08:28:59.582 17366 17366 I TSLocationManager: ╟─ stopOnTerminate: false
05-30 08:28:59.582 17366 17366 I TSLocationManager: ╟─ enabled: true

05-30 08:29:50.722 17366 18016 I flutter : Initializing... 05-30 08:29:50.743 17366 17366 D TSLocationManager: [c.t.f.b.streams.StreamHandler onListen] location 05-30 08:29:50.757 17366 18016 I flutter : Initialization done 05-30 08:29:50.802 17366 17366 D TSLocationManager: [c.t.l.adapter.TSConfig c] ℹ️ Persist config, dirty: [allowIdenticalLocations, debug, desiredAccuracy, distanceFilter, headlessJobService, heartbeatInterval, logLevel, logMaxDays, maxRecordsToPersist, notification, notification.title, notification.text, notification.smallIcon, notification.largeIcon, notification.channelName, startOnBoot, stopOnTerminate] 05-30 08:29:50.808 17366 17366 I TSLocationManager: [c.t.l.service.HeartbeatService b] 05-30 08:29:50.808 17366 17366 I TSLocationManager: 🎾 Start heartbeat (300s) 05-30 08:29:50.814 17366 17366 D TSLocationManager: [c.t.locationmanager.util.b a] 05-30 08:29:50.814 17366 17366 D TSLocationManager: ℹ️ LocationAuthorization: Permission granted 05-30 08:29:50.818 17366 18028 I TSLocationManager: - Enable: true → true, trackingMode: 1 05-30 08:29:50.819 17366 17366 D TSLocationManager: [c.t.l.a.BackgroundGeolocation ready] LocationPermission :true 05-30 08:29:50.821 17366 18028 D TSLocationManager: [c.t.locationmanager.util.b a] 05-30 08:29:50.821 17366 18028 D TSLocationManager: ℹ️ LocationAuthorization: Permission granted 05-30 08:29:50.826 17366 17366 D TSLocationManager: [c.t.locationmanager.util.b a] 05-30 08:29:50.826 17366 17366 D TSLocationManager: ℹ️ LocationAuthorization: Permission granted 05-30 08:29:50.828 17366 18028 I TSLocationManager: [c.t.l.service.HeartbeatService b] 05-30 08:29:50.828 17366 18028 I TSLocationManager: 🎾 Start heartbeat (300s) 05-30 08:29:50.833 17366 18028 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a] 05-30 08:29:50.833 17366 18028 I TSLocationManager: 🎾 Start motion-activity updates 05-30 08:29:50.838 17366 18028 D TSLocationManager: [c.t.l.http.HttpService startMonitoringConnectivityChanges] 05-30 08:29:50.838 17366 18028 D TSLocationManager: 🎾 Start monitoring connectivity changes 05-30 08:29:50.841 17366 18028 D TSLocationManager: [c.t.locationmanager.device.a c] 05-30 08:29:50.841 17366 18028 D TSLocationManager: 🎾 Start monitoring powersave changes 05-30 08:29:50.884 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:50.898 17366 17366 D TSLocationManager: [c.t.l.s.ActivityRecognitionService a] 05-30 08:29:50.898 17366 17366 D TSLocationManager: 🚘 ️DetectedActivity [type=STILL, confidence=100] 05-30 08:29:50.910 17366 17366 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy] 05-30 08:29:50.910 17366 17366 D TSLocationManager: 🔴 ActivityRecognitionService destroyed 05-30 08:29:50.929 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:50.939 17366 17366 I TSLocationManager: [c.t.l.s.LocationRequestService b] 05-30 08:29:50.939 17366 17366 I TSLocationManager: ℹ️ Location availability: true 05-30 08:29:50.942 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:50.953 17366 17366 I TSLocationManager: [c.t.l.s.LocationRequestService b] 05-30 08:29:50.953 17366 17366 I TSLocationManager: ℹ️ Location availability: true 05-30 08:29:50.958 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:50.966 17366 17366 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a] 05-30 08:29:50.966 17366 17366 I TSLocationManager: ╔═════════════════════════════════════════════ 05-30 08:29:50.966 17366 17366 I TSLocationManager: ║ Motion Transition Result 05-30 08:29:50.966 17366 17366 I TSLocationManager: ╠═════════════════════════════════════════════ 05-30 08:29:50.966 17366 17366 I TSLocationManager: ╟─ 🎾 ENTER: still 05-30 08:29:50.966 17366 17366 I TSLocationManager: ╚═════════════════════════════════════════════ 05-30 08:29:51.069 17366 17366 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy] 05-30 08:29:51.069 17366 17366 D TSLocationManager: 🔴 ActivityRecognitionService destroyed 05-30 08:29:52.014 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:52.030 17366 17366 I TSLocationManager: [c.t.l.s.LocationRequestService a] 05-30 08:29:52.030 17366 17366 I TSLocationManager: ╔═════════════════════════════════════════════ 05-30 08:29:52.030 17366 17366 I TSLocationManager: ║ getCurrentPosition LocationResult: 14 05-30 08:29:52.030 17366 17366 I TSLocationManager: ╠═════════════════════════════════════════════ 05-30 08:29:52.030 17366 17366 I TSLocationManager: ╟─ 📍 Location[fused 45.519258,-73.616957 hAcc=15 et=+21h17m0s390ms alt=44.599998474121094 vAcc=2 sAcc=??? bAcc=??? {Bundle[mParcelledData.dataSize=52]}], age: 1087ms, time: 1559219390941 05-30 08:29:52.060 17366 17366 I TSLocationManager: [c.t.l.l.TSLocationManager onSingleLocationResult] 05-30 08:29:52.060 17366 17366 I TSLocationManager: 🔵 Acquired current position 05-30 08:29:52.062 17366 17366 D TSLocationManager: [c.t.l.l.TSLocationManager calculateMedianAccuracy] Median accuracy: 15.382 05-30 08:29:52.069 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:52.076 17366 17366 I TSLocationManager: [c.t.l.s.LocationRequestService a] 05-30 08:29:52.076 17366 17366 I TSLocationManager: ╔═════════════════════════════════════════════ 05-30 08:29:52.076 17366 17366 I TSLocationManager: ║ providerchange LocationResult: 15 05-30 08:29:52.076 17366 17366 I TSLocationManager: ╠═════════════════════════════════════════════ 05-30 08:29:52.076 17366 17366 I TSLocationManager: ╟─ 📍 Location[fused 45.519258,-73.616957 hAcc=15 et=+21h17m0s390ms alt=44.599998474121094 vAcc=2 sAcc=??? bAcc=??? {Bundle[mParcelledData.dataSize=52]}], age: 1134ms, time: 1559219390941 05-30 08:29:52.081 17366 17366 I TSLocationManager: [c.t.l.l.TSLocationManager onSingleLocationResult] 05-30 08:29:52.081 17366 17366 I TSLocationManager: 🔵 Acquired providerchange position 05-30 08:29:52.084 17366 17366 D TSLocationManager: [c.t.l.l.TSLocationManager calculateMedianAccuracy] Median accuracy: 15.304 05-30 08:29:52.091 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:52.093 17366 18028 I TSLocationManager: [c.t.l.data.sqlite.b persist] 05-30 08:29:52.093 17366 18028 I TSLocationManager: ✅ INSERT: 4ad5ba41-9317-41cf-8249-e05ec59263bb 05-30 08:29:52.096 17366 18028 D TSLocationManager: [c.t.l.data.sqlite.b a] 05-30 08:29:52.096 17366 18028 D TSLocationManager: ℹ️ SHRINK: 10 05-30 08:29:52.100 17366 17366 D TSLocationManager: [c.t.l.g.TSGeofenceManager startMonitoringStationaryRegion] 05-30 08:29:52.100 17366 17366 D TSLocationManager: 🎾 Start monitoring stationary region (radius: 150.0 meters) 05-30 08:29:52.105 17366 17366 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a] 05-30 08:29:52.105 17366 17366 I TSLocationManager: 🎾 Start motion-activity updates 05-30 08:29:52.109 2063 2870 I GeofencerStateMachine: addGeofences called by com.example.foo 05-30 08:29:52.110 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:52.111 2063 3268 I GeofencerStateMachine: Use last location to update newly added Geofences. 05-30 08:29:52.121 17366 18016 I flutter : [location] - [Location {odometer: 0.0, activity: {confidence: 100, type: still}, extras: {}, battery: {level: 0.97, is_charging: true}, uuid: 86fd2cca-6dd9-468c-967f-e4d6f6efc6e5, coords: {altitude: 44.6, heading: -1.0, latitude: 45.5192576, accuracy: 15.3, speed: -1.0, longitude: -73.6169566}, is_moving: false, timestamp: 2019-05-30T12:29:50.941Z}] 05-30 08:29:52.122 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:52.124 17366 18016 I flutter : [location] - [Location {odometer: 0.0, activity: {confidence: 100, type: still}, provider: {gps: true, enabled: true, network: true, status: 3}, extras: {}, event: providerchange, battery: {level: 0.97, is_charging: true}, uuid: 4ad5ba41-9317-41cf-8249-e05ec59263bb, coords: {altitude: 44.6, heading: -1.0, latitude: 45.5192576, accuracy: 15.3, speed: -1.0, longitude: -73.6169566}, is_moving: false, timestamp: 2019-05-30T12:29:50.941Z}] 05-30 08:29:52.135 17366 17366 I TSLocationManager: [c.t.l.service.TrackingService f] 05-30 08:29:52.135 17366 17366 I TSLocationManager: ╔═════════════════════════════════════════════ 05-30 08:29:52.135 17366 17366 I TSLocationManager: ║ TrackingService motionchange: false 05-30 08:29:52.135 17366 17366 I TSLocationManager: ╠═════════════════════════════════════════════ 05-30 08:29:52.140 17366 17366 D TSLocationManager: [c.t.l.service.TrackingService onDestroy] 05-30 08:29:52.140 17366 17366 D TSLocationManager: 🔴 TrackingService destroyed 05-30 08:29:52.157 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:52.165 17366 17366 D TSLocationManager: [c.t.l.s.ActivityRecognitionService a] 05-30 08:29:52.165 17366 17366 D TSLocationManager: 🚘 ️DetectedActivity [type=STILL, confidence=100] 05-30 08:29:52.171 17366 17366 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy] 05-30 08:29:52.171 17366 17366 D TSLocationManager: 🔴 ActivityRecognitionService destroyed 05-30 08:29:52.200 17366 17366 W TSLocationManager: [c.t.l.s.ForegroundNotification a] Failed to find notificationLargeIcon: drawable/ic_launcher 05-30 08:29:52.213 17366 17366 I TSLocationManager: [c.t.l.s.ActivityRecognitionService a] 05-30 08:29:52.213 17366 17366 I TSLocationManager: ╔═════════════════════════════════════════════ 05-30 08:29:52.213 17366 17366 I TSLocationManager: ║ Motion Transition Result 05-30 08:29:52.213 17366 17366 I TSLocationManager: ╠═════════════════════════════════════════════ 05-30 08:29:52.213 17366 17366 I TSLocationManager: ╟─ 🎾 ENTER: still 05-30 08:29:52.213 17366 17366 I TSLocationManager: ╚═════════════════════════════════════════════ 05-30 08:29:52.317 17366 17366 D TSLocationManager: [c.t.l.s.ActivityRecognitionService onDestroy] 05-30 08:29:52.317 17366 17366 D TSLocationManager: 🔴 ActivityRecognitionService destroyed

christocracy commented 5 years ago

$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.5 18F132, locale en-CA)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1) [✓] Android Studio (version 3.3) [✓] Connected device (4 available)

darioxtx commented 5 years ago

Flutter tries to save app state when closing app, but it seems does not work well using Singletons. I changed singleton pattern to bloc and issue gone.