颤动检测杀死应用程序

Kod*_*ata 13 flutter

我想知道是否有可能检测到杀死应用程序.让我们说在聊天应用程序中,当用户使用onWillPop离开聊天室时,我能够获得时间戳.但是,如果用户直接从聊天室中删除应用程序,它将不会被解雇.那么有没有办法检测到它?
或者任何建议以不同的方式获得时间戳?

Gün*_*uer 14

另请参阅https://flutter.io/flutter-for-android/#how-do-i-listen-to-android-activity-lifecycle-events

您可以侦听不活动,已暂停和已暂停的内容。这可能为时过早,但通常最好过早且频繁地进行一些清理,而不是根本不做:

WidgetsBinding.instance.addObserver(LifecycleEventHandler(
    suspendingCallBack: () async => widget.appController.persistState(),
    resumeCallBack: () async {
      _log.finest('resume...');
    }));
Run Code Online (Sandbox Code Playgroud)
class LifecycleEventHandler extends WidgetsBindingObserver {
  LifecycleEventHandler({this.resumeCallBack, this.suspendingCallBack});

  final FutureVoidCallback resumeCallBack;
  final FutureVoidCallback suspendingCallBack;

//  @override
//  Future<bool> didPopRoute()

//  @override
//  void didHaveMemoryPressure()

  @override
  Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
    switch (state) {
      case AppLifecycleState.inactive:
      case AppLifecycleState.paused:
      case AppLifecycleState.suspending:
        await suspendingCallBack();
        break;
      case AppLifecycleState.resumed:
        await resumeCallBack();
        break;
    }
    _log.finest('''
=============================================================
               $state
=============================================================
''');
  }

//  @override
//  void didChangeLocale(Locale locale)

//  @override
//  void didChangeTextScaleFactor()

//  @override
//  void didChangeMetrics();

//  @override
//  Future<bool> didPushRoute(String route)
}
Run Code Online (Sandbox Code Playgroud)