Android use of mobile data when in background - android

I have developed a hybrid app running on Android, that successfully monitors the users location and displays it to the user as a moving icon on a map. This part of the app is all written in javascript and works inside a webview. The webview also communicates with my remote server to share the user's location with other users of the same app.
Up until Android Nougat this all works even when the app is backgrounded for several days. When the user returns to the app they can see where they have been with timestamps at each point. And all the other app users can see where everyone is, even if they are no actively using the app.
From Android Oreo onwards, I had to move the location tracking to a background service to get it to continue in the background and I have tested this to be still working fine even with the app in the background for a long period. Returning to the app, the user can still see where they have been. However the remote communications to the server, on Android Oreo and later, cease after approximately 2 minutes in the background.
Please could someone explain why this is, and what I could (if anything) do about it?
What is the restriction that I am running into and where is it documented on Android developer? I have set the app as not to be limited in settings/network/data saver and this makes no difference.
Would it make a difference if I replaced the webview XMLHttpRequest with similar code in background service, using volley or something similar?
All help very much appreciated.

Although I have not discovered what restriction I am running foul of, I have found that by moving the http request from the web view to the background service using volley, the server continues to be updated whether or not the application is in the foreground.
Only tested so far on Android 8,9 and 10 in the emulator. Testing soon on a real device

Related

Flutter app stay running while in background

I have an app I have building that is giving navigation from a location to a location. Contstantly tracking where the user is using GPS data in order to give good Directional information. Currently if a user switches from our app to another app or goes to the Android home screen, after one minute Android turns off our app for performance reasons.
I have tried using an Isolate but like flutter this gets shutdown. Next step were to use a kotlin service to handle background things but i wanted to check if anyone had done this in dart yet?
Also this is not an app that will be in the play store or on public devices. It is going on special devices that we control and are less worried about memory usage as this will be the main app ran on them.
as mentioned above in the comment by #galloper background_fetch is the thing you need, it has a method called BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask); where backgroundFetchHeadlessTask is a function that will keep running even when the app is close, i used this in my app to stream location info to server.

Doing a background task in android when app is closed or phone in doze mode

I want to do an http request each day and showing a notification based on the http response.
I tried to use any option but nothing really works.
I am testing my app on Oneplus 3T android 8.1
I tried to use AlarmManager with the following methods setExactAndAllowWhileIdle and setAlarmClock but those methods sometimes firing and sometimes isn't and I don't understand why they aren't persistent. From what I read from Android 8 AlarmManager ins't persistent because the Doze Mode.
I then tried to use WorkManager with OneTimeWorkRequest but this solution get killed when I closing my app but, when I set my app to not be optimized by the phone the WorkManager keeps running even if I closing my app.
I want to find a solution that does work in any situation (Doze mode, app closed, etc) and isn't requiring to ask the user to remove my app from the phone's battery optimization. I know that it is possible because I have apps that show me notifications when I receive a new massage like Instagram, Facebook, Gmail etc (from what I understand those apps using FCM to do so but I am not sure about that and if they are I am not going to use Firebase only for that)
I searched for a solution for four days long and didn't find anything.

Service not running in background after swiping out application

I am using service for sending current location of device to server continuously in background, but service is also getting killed when I swipe out the application on some phones. It's working if I remove restriction of running background services from Phone settings to the app. I will be thankful, If someone provide solution of removing this restriction programatically.
Every Phone manufacturer has it's own settings for background processing apps. As there are many android device manufacturers it will be difficult to check for every device group. I'm facing the same issue for my app. It will be better if you ask to check is there any setting regarding background services in their device.

Combination of Android service, Cordova background plugin and Skype O365 sdk does not working after few hours while running in background?

I am working on ionic platform and making one Android and iOS application.
Application requirement:
Skype for business O365 login will be there for user and then minimizing the application it will change the status of user like busy, available and note as well on regular interval.
What I have done:
I have used Cordova background mode and Skype websdk.It's logging in fine and setting the status fine while using in foreground.
Problem I am facing:
If I put application in background mode then the status is setting for few minutes but after that somehow it's not setting the status.
So, I am thinking that might be some scenarios:
Might the Android or iOS stopping the background service.
Might the cordova background plugin not working properly.
Might the Skype websdk stops after some time while running in background
Getting this error after the 404 not found code.
https://webpooldb41e02.infra.lync.com/ucwa/oauth/v1/applications/1145363530/me/reportMyActivity
I am researching for the above aspects as well.
I had a same problem. Its not about Background plugin. I found that Skype SDK somehow stops working if it stays in same network for more then around 4800 seconds.
What I did is I signed out and signed Back In user with SetInterval. So token will refreshed and It worked for me. You can use signet and signIn with setInterval of 4000 second or so.

How does background data transfer work?

I have a problem understanding how the 'Restrict background data' setting in Android really works. I always thought that with this restriction turned on, only visible applications could download data, but currently I'm developing an application that has shaken this understanding... My application registers an alarm in AlarmService to start a background IntentService every 5 minutes. This service will then download the latest financial quotes. What is surprising to me, is that no matter what the 'Restrict background data' setting is, the service is able to download the data over WIFI (didn't try with cellular interface yet).
So my question is, how does 'Restrict background data' setting in Android really work? Also should I worry about it in the case of my application and are there any differences in the behaviour of this option depending on the version of Android (I've checked on 2.3.3 Samsung Galaxy SII)?
how does 'Restrict background data' setting in Android really work?
For Android 1.x/2.x/3.x, it was an "opt-in" setting for developers. Developers should check to see if background data is disallowed and not do it in the background if it is.
For Android 4.0+, Android basically blocks you from doing Internet access if the user's profile for your app calls for that (e.g., you have exceeded an allotted bandwidth threshold).
For Ice Cream Sandwich it specifically says that the restrict background option is for data only and does not restrict for WiFi.

Categories

Resources