Service not running in background after swiping out application - android

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.

Related

Keep Flutter application active on device at all times, possible?

A client of mine is requesting for a very specific functionality, to keep the application always active, even after the user force kills it. He wants to ensure that the users have the application active at any time while using the device on which it is installed (the devices are managed in a constrained environment).
I've done some research on it, and already enabled background services for sending the user's location, but if they force kill the app then we are unable to send locations to the server. We've seen other apps do it, but wonder how they do it.
According to https://stackoverflow.com/a/34573169/640907 it should be possible in Android. We also found https://ssaurel.medium.com/how-to-auto-restart-an-android-application-after-a-crash-or-a-force-close-error-1a361677c0ce but I don't think this will work for our use-case, as the user can close the application without "force kill" aswell..
Anyone knows how to achieve this for a Flutter application?

Android use of mobile data when in background

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

How to make sure a service that runs when the Application is closed does not get killed?

I am developing a Fitness Application as part of my Bachelor Thesis, and want to keep track of step counts even when the application is completely closed. For this I am currently starting a service that utilises the built in Sensors "Step Counter" and "Step Detector". After some testing I found out that sometimes my Service gets killed and no longer keeps track of the steps taken. I left the phone on my desk overnight and walked around in the morning then I opened the application and the steps I took in the morning were not tracked, whereas when I close the application and immediatly start walking the tracking of steps still works.
Is there a way to make sure that my Service does not get killed?
Would the use of a Foreground Service solve my issue and are there any alternatives to using a foreground service?
Foreground Service is the only way if you want to assure that the service will not be killed.
The reason for this is that the foreground service always shows a notification to the user and can be killed by the user if he wants to, this is especially important if you want to know for sure what runs on your device.
All previous methods of making permanent running services are deprecated starting from android 9, when a new privacy policy was introduced.
Basically you need to keep service running in the background,
Here is the workaround to achieve this
https://stackoverflow.com/a/58162451/7579041
above link is useful for Stock ROM & Custom ROM Devices like OnePlus, OPPO, VIVO, etc
I hope this will help you out

Huawei power saver app allowing app to run in background

I've developed an app which receives push notifications from Parse. The app is designed to run in background so that notifications can be received even when app is closed.
But we are facing challenge with Huawei's devices due to its custom "power savings" feature which detects the app as power intensive and hence clears it from memory when screen is locked.
Are there any known methods to prevent the app from being restricted or to add it to "Protected Apps" list upon installation?
Note: We begun with GCM notificatoins, but after learning that GCM's notification deliverability is flaky, we moved on to Parse.com's PPNS and then this new roadblock.
We cant do much except detect the device,if device is huawei warn the user about propably issue if the desired app wont be added to protected apps hence this is the only way to do what we need.No other ways available and i reckon it will never be!

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