Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state management in foreground service isolate #5

Open
yakupbaser opened this issue Jan 10, 2021 · 8 comments
Open

state management in foreground service isolate #5

yakupbaser opened this issue Jan 10, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@yakupbaser
Copy link

how can i send a state to foreground service and get same state from it? May be you can update your plugin about it.

Please check it: fluttercommunity/get_it#145

and i made an example for this problem: https://github.com/yakupbaser/demogetit

@SayWut
Copy link
Owner

SayWut commented Jan 10, 2021

First of all I broke my arm so it will take time for me to fix something

Second, in flutter to send data between the android OS and the dart code you need to work with channels which works over an engine. When the app is starts there is a main engine that created with it, but to make the task work when the flutter app is closed I need to create a different engine which isn't communicate with the main engine. In the end it means that you need to treat the task function like another flutter app, you need to initialize everything again in the task function

Which means that what you want me to do isn't possible

I hope that it makes sense and sorry for bad English

@yakupbaser
Copy link
Author

i think, you should add startTaskFunctionJustForOnce

@SayWut
Copy link
Owner

SayWut commented Jan 14, 2021

i think, you should add startTaskFunctionJustForOnce

You mean creating a task that will be executed only once, and it will execute different code then the periodic task?

@yakupbaser
Copy link
Author

pls check https://pub.dev/packages/workmanager

it supports:
One off task : runs only once
Periodic tasks : runs indefinitely on a regular basis

@SayWut
Copy link
Owner

SayWut commented Jan 15, 2021

but the plugins purpose is different

In the WorkManager you can register multiple tasks (periodic and one off tasks) which will be executed at different times and this is the purpose of the WorkManager and the plugin is just an api to the built in WorkManager in android it's like TaskScheduler in windows.

My plugin purpose is to create a non stop running foreground service and if I implement an option to execute multiple tasks so it's like creating the built in WorManager of android but thru a foreground service so I don't see a reason for this.

If you want me to add button action or custom foreground layout etc I can add those because I do see this as something that my plugin should do

btw
I actually created this foreground service plugin to use it in my app because of the WorkManager. In android if your app is closed and you registered tasks in the WorkManager then after a period if time your tasks will be killed by the battery's phone optimization so I use this foreground service to keep an instance of my app running so my WorkManager tasks will not be killed

@yakupbaser
Copy link
Author

yakupbaser commented Jan 15, 2021

But it has to be a task function runs only once option. For example i have a function. its calculating finish time is 2 minutes and it has backend operations. i want to run it only ones with foreground servise. How can i make this?

@SayWut
Copy link
Owner

SayWut commented Jan 15, 2021

But it has to be a task function runs only once option. For example i have a function. its calculating finish time is 2 minutes and it has backend operations. i want to run it only ones with foreground servise. How can i make this?

I see.
I will implement something

You can now create a periodic task and kill it after it executed

@SayWut
Copy link
Owner

SayWut commented Jan 19, 2021

I'm in a dilemma

I don't know if to create the tasks like so:
you can create only one task periodic or one task off
or
you can create periodic and one off task

what do you say?

@SayWut SayWut added the enhancement New feature or request label Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants