flutter_workmanager icon indicating copy to clipboard operation
flutter_workmanager copied to clipboard

Not Working When App is killed Or Terminated

Open mahmoudelgharabawi opened this issue 1 year ago • 12 comments

the package work fine in foreground and in background But When App killed No Thing Happen ??

package version

workmanager: ^0.5.1

flutter version 3.7.7

The Code I try To run

`import 'package:flutter/material.dart'; import 'package:workmanager/workmanager.dart';

const simplePeriodicTask = "be.tramckrijte.workmanagerExample.simplePeriodicTask";

@pragma('vm:entry-point') void callbackDispatcher() { Workmanager().executeTask((taskName, inputData) { print('Inside WorkManager execute'); return Future.value(true); }); }

void main() { runApp(const MyApp()); }

class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key);

@override State<MyApp> createState() => _MyAppState(); }

class _MyAppState extends State<MyApp> { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(), ); } }

class MyHomePage extends StatefulWidget { const MyHomePage({Key? key}) : super(key: key);

@override State<MyHomePage> createState() => _MyHomePageState(); }

class _MyHomePageState extends State<MyHomePage> { @override void initState() { initWorkManager(); super.initState(); }

void initWorkManager() async { try { print('iniside try,,,,,,,,,,,catch workmanager block'); Workmanager() .initialize(callbackDispatcher, isInDebugMode: true) .then((_) async { await Workmanager().registerPeriodicTask( simplePeriodicTask, simplePeriodicTask, initialDelay: Duration(seconds: 10), ); }); } catch (e) { print('Exception in register work manager'); } }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( centerTitle: true, title: const Text("Work manager Example"), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[], ), ), ); } } `

mahmoudelgharabawi avatar Mar 16 '23 11:03 mahmoudelgharabawi

Same

A7MeDG0L0L avatar Mar 16 '23 11:03 A7MeDG0L0L

same problem me to , Flutter 3.7.7

TOMER628 avatar Mar 20 '23 16:03 TOMER628

The Target platform is not specified, but in the case of iOS, It's not a bug but expected behavior.

When an app is explicitly terminated by the user or the system, iOS will stop all background tasks for this process. This is by design.

Watch this https://developer.apple.com/videos/play/wwdc2019/707 and https://developer.apple.com/videos/play/wwdc2020/10063

MadGeorge avatar Apr 05 '23 08:04 MadGeorge

me too. not working only on android case when terminated app flutter version 3.3.1

Saharatt593 avatar Apr 28 '23 12:04 Saharatt593

me too in registerPeriodicTask in

Flutter 3.7.7 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 2ad6cd72c0 (8 weeks ago) • 2023-03-08 09:41:59 -0800
Engine • revision 1837b5be5f
Tools • Dart 2.19.4 • DevTools 2.20.1

Saeeed-B avatar Apr 30 '23 11:04 Saeeed-B

me too. not working only on android case when terminated app flutter version 3.3.1

update After updating flutter to 3.7.12 it works. If using the emulater after installing the app for the first time. app must be opened and terminated 1 time. after that it will work even after restarting the device. If using a real device, there is no problem.

Saharatt593 avatar May 02 '23 10:05 Saharatt593

me too. not working only on android case when terminated app flutter version 3.3.1

update After updating flutter to 3.7.12 it works. If using the emulater after installing the app for the first time. app must be opened and terminated 1 time. after that it will work even after restarting the device. If using a real device, there is no problem.

thanks. you right ,WORK for me well :)

EDIT: somthing strange.. that background work just if i kill the App and then when i reopen it the WorkMannager do the work.. how that can be. what can i do ?

TOMER628 avatar May 02 '23 13:05 TOMER628

me too. not working only on android case when terminated app flutter version 3.3.1

update After updating flutter to 3.7.12 it works. If using the emulater after installing the app for the first time. app must be opened and terminated 1 time. after that it will work even after restarting the device. If using a real device, there is no problem.

thanks. you right ,WORK for me well :)

EDIT: somthing strange.. that background work just if i kill the App and then when i reopen it the WorkMannager do the work.. how that can be. what can i do ?

The same thing happened to me flutter version 3.13.7 work manager work only when I open app send notification and after 15 min send another one after that it doesn't send any notification and when app is terminated not worked anymore

Salmakhaled123 avatar Oct 16 '23 07:10 Salmakhaled123

Is there any progress in this case?

anasmano avatar Feb 21 '24 02:02 anasmano

Any updates on this? I am using Channel stable, 3.19.2, on macOS 13.6.4 22G513 darwin-arm64

My worker triggers when I turn on the Internet. This works well when the app is in Foreground or Background. But, when the app is either closed or terminated, and I turn on the Internet, I see the Debug notification from my Worker. But is executed only when I attempt to open the app. Right when I open the app, the Work executes and Is successful.

KamathVishak96 avatar May 03 '24 13:05 KamathVishak96