Background Services #3

Open
opened 2022-10-14 17:41:23 +00:00 by Lonami · 1 comment

grammers is a Long Running (May take some time to complete), Impersistent work (No longer scheduled after the process ends). It needs to run pretty much all the time in order to receive socket updates from Telegram. However, if the process ends, we wouldn't really want it to relaunch itself to keep working. It should only work for as long as the user is interested.

However, the Guide to background work says:

Long-running and deferrable impersistent work: You should not use long-running and deferrable impersistent work. You should instead complete such tasks through persistent work using WorkManager.

It tends to talk about durations such as "10 minutes", "15 minutes", but grammers may need to run for hours, or even days.

Perhaps it would be interesting to learn how DrKLO/Telegram achieves this, or maybe TGX-Android/Telegram-X.

This might also not be "essential" to run once the app is closed if notifications work via Push notifications.

grammers is a Long Running (May take some time to complete), Impersistent work (No longer scheduled after the process ends). It needs to run pretty much all the time in order to receive socket updates from Telegram. However, if the process ends, we wouldn't really want it to relaunch itself to keep working. It should only work for as long as the user is interested. However, the [Guide to background work](https://developer.android.com/guide/background) says: > Long-running and deferrable impersistent work: You should not use long-running and deferrable impersistent work. You should instead complete such tasks through persistent work using WorkManager. It tends to talk about durations such as "10 minutes", "15 minutes", but grammers may need to run for hours, or even days. Perhaps it would be interesting to learn how DrKLO/Telegram achieves this, or maybe TGX-Android/Telegram-X. This might also not be "essential" to run once the app is closed if notifications work via Push notifications.
Poster
Owner

StackOverflow has this to say regarding using threads vs proper services:

Services

-- https://stackoverflow.com/a/2633457

If you need to perform work outside your main thread, but only while the user is interacting with your application, then you should probably instead create a new thread and not a service. For example, if you want to play some music, but only while your activity is running, you might create a thread in onCreate(), start running it in onStart(), then stop it in onStop(). Also consider using AsyncTask or HandlerThread, instead of the traditional Thread class. See the Processes and Threading document for more information about threads.

Remember that if you do use a service, it still runs in your application's main thread by default, so you should still create a new thread within the service if it performs intensive or blocking operations.

https://stackoverflow.com/a/36113161

StackOverflow has this to say regarding using threads vs proper services: > \[Services\] are for running tasks with a lifecycle that is independent of the Activity lifecycle (IE, they may continue after the Activity is closed). > > -- https://stackoverflow.com/a/2633457 > If you need to perform work outside your main thread, but only while the user is interacting with your application, then you should probably instead create a new thread and not a service. For example, if you want to play some music, but only while your activity is running, you might create a thread in onCreate(), start running it in onStart(), then stop it in onStop(). Also consider using AsyncTask or HandlerThread, instead of the traditional Thread class. See the Processes and Threading document for more information about threads. > > Remember that if you do use a service, it still runs in your application's main thread by default, so you should still create a new thread within the service if it performs intensive or blocking operations. > > https://stackoverflow.com/a/36113161
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Lonami/Talaria#3
There is no content yet.