AppLifeCycleState.detached is not called when app is closed quickly #57594
Comments
|
Hi @maheshkumar2150 [ +3 ms] Flutter run key commands.
[ +2 ms] r Hot reload. 🔥🔥🔥
[ +1 ms] R Hot restart.
[ ] h Repeat this help message.
[ ] d Detach (terminate "flutter run" but leave application running).
[ ] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ ] An Observatory debugger and profiler on Pixel 3a is available at: http://127.0.0.1:56690/h8eHhwkXxs0=/
[ +268 ms] I/flutter (25063): initState() called
[+7275 ms] I/flutter (25063): AppLifecycleState.inactive
[ +58 ms] I/flutter (25063): AppLifecycleState.paused
[+2080 ms] I/flutter (25063): AppLifecycleState.resumed
[+1507 ms] I/flutter (25063): AppLifecycleState.inactive
[ +53 ms] I/flutter (25063): AppLifecycleState.paused
[+2081 ms] I/flutter (25063): AppLifecycleState.detached
[ +804 ms] Service protocol connection closed.
[ +3 ms] Lost connection to device.
[ +9 ms] executing: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +8 ms] Exit code 0 from: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +1 ms] 965AY0WP5C tcp:56690 tcp:39929
[ +3 ms] executing: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --remove tcp:56690
[ +16 ms] DevFS: Deleting filesystem on the device (file:///data/user/0/com.example.master/code_cache/masterLAGHAW/master/)
[ +263 ms] Ignored error while cleaning up DevFS: TimeoutException after 0:00:00.250000: Future not completed
[ +9 ms] executing: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +9 ms] Exit code 0 from: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +4 ms] "flutter run" took 54,173ms.
[ +262 ms] Running shutdown hooks
[ +1 ms] Shutdown hook priority 4
[ +3 ms] Shutdown hooks completedoctor[✓] Flutter (Channel master, 1.19.0-2.0.pre.131, on Mac OS X 10.15.4 19E287, locale en-EE)
• Flutter version 1.19.0-2.0.pre.131 at /Users/nevercode/development/flutter_master
• Framework revision 478d4c9c1a (5 hours ago), 2020-05-19 20:22:01 -0700
• Engine revision 2d4e83921d
• Dart version 2.9.0 (build 2.9.0-9.0.dev 40f7a11d89)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/nevercode/Library/Android/sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.9.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.2
[✓] Connected device (3 available)
• Pixel 3a • 965AY0WP5C • android-arm64 • Android 10 (API 29)
• Web Server • web-server • web-javascript • Flutter Tools
• Chrome • chrome • web-javascript • Google Chrome 81.0.4044.138
• No issues found!while with the current stable it behaves as you described [ +3 ms] Flutter run key commands.
[ +2 ms] r Hot reload. 🔥🔥🔥
[ +1 ms] R Hot restart.
[ ] h Repeat this help message.
[ ] d Detach (terminate "flutter run" but leave application running).
[ ] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ ] An Observatory debugger and profiler on Pixel 3a is available at: http://127.0.0.1:56917/ZnQHWAVVOYE=/
[ +20 ms] I/flutter (25520): initState() called
[+5022 ms] I/flutter (25520): AppLifecycleState.inactive
[ +66 ms] I/flutter (25520): AppLifecycleState.paused
[ +596 ms] I/flutter (25520): AppLifecycleState.resumed
[+6270 ms] I/flutter (25520): AppLifecycleState.inactive
[ +41 ms] I/flutter (25520): AppLifecycleState.paused
[+3523 ms] Service protocol connection closed.
[ +2 ms] Lost connection to device.
[ +7 ms] executing: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +10 ms] Exit code 0 from: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ ] 965AY0WP5C tcp:56917 tcp:37845
[ +2 ms] executing: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --remove tcp:56917
[ +16 ms] DevFS: Deleting filesystem on the device (file:///data/user/0/com.example.stable/code_cache/stableLQBTZK/stable/)
[ +2 ms] Sending to VM service: _deleteDevFS({fsName: stable})
[ +263 ms] Ignored error while cleaning up DevFS: TimeoutException after 0:00:00.250000: Future not completed
[ +3 ms] executing: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +8 ms] Exit code 0 from: /Users/nevercode/Library/Android/sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +2 ms] "flutter run" took 51,872ms.doctor[✓] Flutter (Channel stable, v1.17.1, on Mac OS X 10.15.4 19E287, locale en-EE)
• Flutter version 1.17.1 at /Users/nevercode/development/flutter
• Framework revision f7a6a7906b (7 days ago), 2020-05-12 18:39:00 -0700
• Engine revision 6bc433c6b6
• Dart version 2.8.2
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/nevercode/Library/Android/sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.9.0
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.2
[✓] Connected device (1 available)
• Pixel 3a • 965AY0WP5C • android-arm64 • Android 10 (API 29)
• No issues found! |
|
What is latest mater? Is it better than stable version? Because it seems to me. Stable has bug but master hasn't. Can you guide me to upgrade to latest master version? |
|
Hi @maheshkumar2150 If you decide to upgrade please follow the docs |
|
There is no way to use it in stable? |
|
It is working as expected in Android but in iOS, can anyone verify that it is working in master channel in iOS platform? I am using |
|
tagging @pedromassango for visibility |
|
I know this is separate issue working properly in Android |
|
I tested this and here is my feedback Pressed overview button and closed the app by swiping (master channel)
Closed the app by pressing the back button (master channel)
Pressed overview button and closed the app by swiping (stable channel)
Closed the app by pressing the back button (stable channel)
The issueIf you press the overview button and closed the app by swiping quickly, then the only method getting called it
So this is still valid. flutter doctor -v (stable)
flutter doctor -v (master)
|
|
I have the same issue, I tested it in to physical phones
-Samsung j7 prime with android 8:
I think it depends on the android version |
|
I've tested this on iOS Simulators and an iPhone 6 running iOS 12 and |
|
I have the same issue. Any updates? |
|
@haroonkhan9426 |
|
Any update on this? Or is there any other way in Flutter to execute a code(say calling a REST API) just before the app is swiped off(detached)? |
|
@pedromassangocode code sampleimport 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: MyHomePage()));
class MyHomePage extends StatefulWidget {
const MyHomePage() : super(key: const ValueKey('MyHomePage'));
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance?.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance?.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) => print(state);
@override
Widget build(BuildContext context) => Material(
child: WillPopScope(
onWillPop: () async => true,
child: const Center(child: FlutterLogo(size: 80)),
),
);
}
pubspecname: issue
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: truedoctor[✓] Flutter (Channel master, 2.1.0-13.0.pre.232, on Linux, locale en_US.UTF-8)
• Flutter version 2.1.0-13.0.pre.232 at /home/francesco/snap/flutter/common/flutter
• Framework revision 9f49181f40 (2 hours ago), 2021-03-24 15:46:09 +0800
• Engine revision d59a01d2d3
• Dart version 2.13.0 (build 2.13.0-150.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /home/francesco/Android/Sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_SDK_ROOT = /home/francesco/Android/Sdk
• Java binary at: /usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_282-8u282-b08-0ubuntu1~20.04-b08)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• CHROME_EXECUTABLE = /snap/bin/chromium
[✓] Linux toolchain - develop for Linux desktop
• clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
• cmake version 3.10.2
• ninja version 1.8.2
• pkg-config version 0.29.1
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
[✓] Connected device (3 available)
• Pixel 3a (mobile) • 965AY0WP5C • android-arm64 • Android 11 (API 30)
• Linux (desktop) • linux • linux-x64 • Linux
• Chrome (web) • chrome • web-javascript • Chromium 89.0.4389.90 snap
! Doctor found issues in 1 category.
logs[ +90 ms] Syncing files to device Pixel 3a...
[ +1 ms] <- reset
[ ] Compiling dart to kernel with 0 updated files
[ +1 ms] <- recompile package:issue/main.dart 3f5b1d7c-f7d2-4863-8449-5e54397a0088
[ ] <- 3f5b1d7c-f7d2-4863-8449-5e54397a0088
[ +85 ms] Updating files.
[ ] DevFS: Sync finished
[ +1 ms] Syncing files to device Pixel 3a... (completed in 89ms)
[ ] Synced 0.0MB.
[ ] <- accept
[ +17 ms] Connected to _flutterView/0x77f3fbf6f0.
[ +2 ms] Flutter run key commands.
[ +1 ms] r Hot reload. 🔥🔥🔥
[ ] R Hot restart.
[ ] h Repeat this help message.
[ ] d Detach (terminate "flutter run" but leave application running).
[ ] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ ] 💪 Running with sound null safety 💪
[ ] An Observatory debugger and profiler on Pixel 3a is available at: http://127.0.0.1:33431/1KxSGzo4wGQ=/
[ +754 ms] Activating Dart DevTools...
[+2330 ms] Activating Dart DevTools... (completed in 2,330ms)
[ +659 ms] The Flutter DevTools debugger and profiler on Pixel 3a is available at: http://127.0.0.1:9101?uri=http%3A%2F%2F127.0.0.1%3A33431%2F1KxSGzo4wGQ%3D%2F
[+21976 ms] I/flutter (17372): AppLifecycleState.inactive
[ +764 ms] I/flutter (17372): AppLifecycleState.paused
[ +9 ms] I/flutter (17372): AppLifecycleState.detached
[ +29 ms] E/libEGL (17372): call to OpenGL ES API with no current context (logged once per thread)
[+8635 ms] I/flutter (17372): AppLifecycleState.inactive
[ +145 ms] I/flutter (17372): AppLifecycleState.paused
[ +853 ms] Service protocol connection closed.
[ ] Lost connection to device.
[ +2 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +5 ms] Exit code 0 from: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ ] 965AY0WP5C tcp:40587 tcp:38771
[ +1 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C forward --remove tcp:40587
[ +8 ms] DevFS: Deleting filesystem on the device (file:///data/user/0/com.example.issue/code_cache/issueTAFPVQ/issue/)
[ +257 ms] Ignored error while cleaning up DevFS: TimeoutException after 0:00:00.250000: Future not completed
[ +5 ms] executing: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +21 ms] Exit code 0 from: /home/francesco/Android/Sdk/platform-tools/adb -s 965AY0WP5C forward --list
[ +5 ms] "flutter run" took 125,130ms.
[ +168 ms] ensureAnalyticsSent: 162ms
[ +5 ms] Running shutdown hooks
[ +1 ms] Shutdown hooks complete
[ +2 ms] exiting with code 0
@abhin-vicks |
AppLifecycleState.Detached was not printed.
Nothing was saved in database in my real app.
But if i close the app by pressing the back button,
WillPopScore is handling the back button press.
So when the user closed app with overview button, i want to store the last activity in database and i want to resume it when the app opens again.
I am making an app for android and ios.
The above code was tested with android in windows.
The text was updated successfully, but these errors were encountered: