I have written an app using background service, which is launching on specify time. I'm using WakeLocker (CPU only) and for the time I use Handler with delay. During the tests on HTC everything works fine but on Samsung Galaxy S2 everything is weird. Base functionality doesn't work and if service is already active and user run three different apps (not after one, not after two, always after three!!!) My activity is being restarted and doesn't see running service... Why???
Related
I am creating an Android app (Java code) that has an audio call feature.
I managed to make it work using the webRTC framework.
I wanted to make my audio call behave like WhatsApp and Messenger, where those apps keep the audio call running even if the user stops the app from apps history, or starts using another app.
So, I decided to migrate the webRTC code from an Activity to a Foreground Service.
My Audio Call Activity handles the UI, displaying friend photo, name, call timer ...
So I had to make communication between my Activity and my Foreground Service through binding and sending android.os.Message object.
Everything works fine when using SAMSUNG devices, if I kill the app, I could return to the Call activity by clicking the foreground service's notification, and the audio call keeps working until I hang up.
My problem appeared when i used a Xiaomi device (redmi note7), if i kill the app, the audio call stops, cause my Foreground Service is restarted.
Even after enabling "Autostart" from settings.
I searched in here for a solution but all the answers i found didn't satisfy my need, cause i can't just accept my Service being restarted.
If i want to resume the audio call, i have to re-call the friend again !
So, the question is :
How to prevent Xiaomi, Huawei, Oppo ... devices from restarting Foreground Service ?
Which is the case with WhatsAPP, Messenger, Instagram and others.
It's a tricky question since it really depends on the vendor. There is a site which document and rank the vendor according to "how bad" they're handling services and processes. From the site:
...With Android 6 (Marshmallow), Google has introduced Doze mode to the base Android, in an attempt to unify battery saving across the various Android phones. Unfortunately, vendors (e.g. Xiaomi, Huawei, OnePlus or even Samsung..) did not seem to catch that ball and they all have their own battery savers, usually very poorly written, saving battery only superficially with side effects.
The solutions differs from vendor to vendor and from ROM version to another.
For example for Huawei you can overcome the issue in Huawei P20, Huawei P20 Lite, Huawei Mate 10 by Phone settings > Battery > App launch and then set your app to “Manage manually” and make sure everything is turned on. Also for reliable background processes you may need to uninstall PowerGenie (which is a power mgmt. application by Huawei). On the other hand for EMUI 9+ devices you'll have to uninstall PowerGenie via adb
My Android service is not working when the application gets destroyed in Xiaomi devices, but it works perfectly with Motorola devices. Currently I have tested my app with Motorola G 2nd generation, Redmi Note 3 and Mi Pad.
I want to play music in the background when my app is not in recents.
Intent i = new Intent(CollapsingToolbarActivity.this, SongService.class);
startService(i);
well, i got your point, may be u are missing with permission in security app of xiaomi devices. you must allow your app to autostart. that will prevent your service from destroying.
#K. Gandhi He is not saying the app is destroying when using xiaomi device, he says that onDestroy(); seems not working on xiaomi device.
#meeta mastani You have to be clear on your question, but as I understand your question, You are using ForegroundService that you want to run your app even when onDestoy(); is being called or the app is closed.
Answer:
Maybe you are using heavy work on your thread, you have to consider using asyncTask, BackgroundThread, BackgroundService and ForegroundService.
asyncTask - for network operations (internet).
BackgroundThread - for heavy work, but when phone sleeps or displays
turned off, your app will not run or music will not play if you are
making music app.
BackgroundService - your app is in the background but still active
(minimize)
ForegroundService - you app is close or destroy but still working or
playing music.
I developed an android application that starts an android background service. This service sets alarms on the selected time instances. This application and the service is working absolutely fine on android emulator. Works as I expected it to. But the strange thing happens when I installed this application at my android phone. The application worked fine, it started the android service too. But nothing happened from there on. I checked the settings-apps-running apps at my phone. It showed that the service is running on phone. But the thing that I expected from the service was to ring alarms at selected time instances, which it didn't at my phone. I have a samsung galaxy nexus phone. Can you please diagnose what is the problem actually?
Hi I got a problem with my app. App is tracking the user road by GPS. It getting only start point and with each next point calculate distance and increase time. Everything is working great on my HTC Wildfire (with CMD7 2.3.7), Samsung SIII and Galaxy Tab 10.1.
When user start tracking, the app is finishing current activity and start new process with service in background. In the same time start new activity with small animation and put ongoing status in notification area. Everything cool, but problem starts the user is trying app on HTC one series. I can't describle how it behave, cause I don't have this phone and can't reproduce the bug.
Any of you heard anything about memory managing in HTC sense? I read some article that HTC one has this kind a feature.
Or it there is any way to test particular device on emulator?
Thanks for any help.
Make sure you are calling the Service#startForeground method to give your Service foreground scheduling priority. You can find it documented on the Service class:
http://developer.android.com/reference/android/app/Service.html
I have seen background services not get killed by using this on the One series.
Is there any way of running 2 (or potentially more) applications on the emulator at the same time?
I have an application that obtains its data from another application, therefore I want to modify data in application A and then see how application B handles it.
I'm intending to have some kind of "slider" on application A, therefore I need them both to be running at the same time to see the "slider" on application B update.
You can't have UI threads of two applications running at the same time, but if one of your apps has a background service, that can be running while the UI thread of the other is active. This service could put a notification in the status bar to signify that the data has been updated (actually, I think it's now required that a background service have something in the status bar anyway).
I believe you can also create a "toast" pop-up notification from a background service.
If it's just for testing, your background service can also write messages to the logs which you can see with logcat.
You can use the emulator like a normal phone, so you can run as many apps at the same time as you want. When you say "running", are you talking about "debugging"? You can install any number of apps using adb install, or by just running it through Eclipse. Running a new app won't stop the previous one (besides, you can always go to the app menu and start your other app).