Element does not stay running in background
See original GitHub issueDescribe the bug As of late (a couple of F-Droid releases ago, I do not have any idea when it started, but couldn’t have been more than a month ago), Element-dbg doesn’t stay running in the background. I.e. if I change to another activity (this is on Android 8, so #1737 doesn’t seem relevant), then Android kills Element. If I start the app again, the startup spinner appears, and I have to wait for the client to sync with the homeserver. I obviously also don’t get any notifications meanwhile.
To Reproduce
- Start Element
- Change to another activity, e.g. Firefox
- After a while, switch back to Element (or start it again).
Expected behavior
The app used to maintain the connection/sync, so that I would get notifications, and wouldn’t need to wait for a resync.
Smartphone (please complete the following information):
- Device: Galaxys S7 Edge
- OS: Android 8.0 (Custom ROM)
Additional context
- App version and store: 1.0.8-dev [206182990] (F-b160) develop
- Homeserver:
matrix.madduck.net
Issue Analytics
- State:
- Created 3 years ago
- Reactions:13
- Comments:33 (6 by maintainers)
Top Results From Across the Web
shell - I am using `&`: why isn't the process running in ...
Disassociate the backgrounded program from your shell. Use the disown command after backgrounding your process. · Use logout (or Ctrl + d )...
Read more >4 reasons your z-index isn't working (and how to fix it)
It seems simple at first- a higher z-index number means the element will be on top of elements with lower z-index numbers.
Read more >CSS Background image not loading
Do 1 thing..make an Inspect element in chrome, select the body tag & then click on the img in the body style.
Read more >background-attachment - CSS: Cascading Style Sheets | MDN
The background-attachment CSS property sets whether a background image's position is fixed within the viewport, or scrolls with its ...
Read more >HTML Video element, not working after iosSafari15 update
I have had a similar problem. I suggest you check your CSS, in my case, passing a video from fixed to absolute position...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have taken yesterday and today to take a look at the current sync implementation. I have only taken a look at the real time sync code. It is made using alarms. The sync process with the matrix server itself is called from within the service. Before the service ends an alarm is set into the future to retrigger the sync service. The alarm is captured by a broadcast receiver which then (re)starts the service and the whole thing starts again. As with all services since one of the android versions they must start in the foreground and display a notification within 10s if i remember right. This is happening and I can see the notification icon popping up and being removed again.
But I noticed that sometimes I get an application not responding error on the sync service classes when the service is started meaning it is not calling startForeground fast enough. This results in the sync service not being started hence not being able to set a new alarm for the next sync. The sync cycle stops. I did not investigate why.
I also noticed that on my old Moto G3 with only 2GB Ram acitivities and services are killed and restarted quite often. Especially when I use the browser or NewPipe. This is quite “normal” but might point in the direction of the problem that the situation we have here is one of those corner cases. Low powered old devices with not much Ram. Meaning the timing does not work as with newer phones. I know people using the fdroid version where the sync works without any problems. All of them have modern phones. There also might be a correlation with Lineage as it can be that this is used especially on older phones.
I have implemented a patch. Well quite literally as it is not fixing the cause but the symptom. The patch creates a new sticky guard service that is (re)starting the sync services (VectorSyncService) every 1min. No matter if it is still running or not. Android will not restart/start a 2nd service anyways. The guard service is persistent and shows a notification icon as android requests it. Even if the guard services crashes it will be restarted by android (and not an alarm that might not be there anymore). This works since a few hours. Longer than I have ever seen. I hope that with concentrating on the symptom also other crash reasons on other phones can be fixed. The brave can download the patched fdroid version here. It was made from the current development branch using the grade task assembleRelease. Feedback welcome.
I really wish this issue would get some sort of developer response or at least prioritization. It’s quite literally preventing F-Droid users from using Element in its full capacity as a messenger on newer Android versions that impose heavy restrictions on background services. Other apps successfully circumvent this by using a persistent foreground notification. Perhaps
WorkManager
from Android Jetpack could work as well?