Im currently fixing bugs when my app is not the main active app. Most devices i get a PAUSE message, LOST messages etc. These are all as I expect. The thing i dont get is on the Moto G device i always get a destroy message when returning to the app menus etc, or the device is put to sleep.
Is there any reason for this? I am fixing it up, but it seems harsh to have to destroy the app just because you get a phone call or sleep the device, its not like im loading up another complex game or anything
The Moto G appears to have rather aggressive memory management. Android has a low memory killer, which determines which processes to kill depending on device configurations.
While the Moto G does have 1GB of RAM, the minfree settings applied by Motorola seem to kill apps on background.
There are instructions on the web as to how to address this as a user, but as a developer, it is likely best to save your state when you are backgrounded in onPause().
http://m.androidcentral.com/fine-tuning-minfree-settings-improving-androids-multi-tasking
http://developer.android.com/reference/android/app/Activity.html#ProcessLifecycle
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
I am developing two apps:
-> App A: it connects to a Bluetooth device, retrieve some data, process this data and broadcast an intent to App B
-> App B: it receives this intent and shows the results.
App A must keep running in order to keep sending data to App B.
Everything was working fine until this week when I made some visual changes and update my android device to V7.0.
Now, My App A stops (DEAD message in debugging window in android studio) when I switch to App B and see the results. If I change back to App A, current activity restarts itself and it works normally once again.
I do not get any exception or error message in android studio's debug window.
Any idea or information about this issue. I must say I have read a lot of questions and documentation but I can not find the reason of this issue.
(sorry for bad English)
Everything was working fine until this week when I made some visual
changes and update my android device to V7.0.
7.0 has introduced numerous changes aimed at improving battery life. Your App A is likely suffering from these changes, particularly if it was memory / cpu intensive, which it sounds like it might be.
App A must keep running in order to keep sending data to App B.
If that's the case, you probably want a make App A a foreground Service to ensure it keeps running.
Architecturally this probably makes more sense anyway if your use case is to have App B open while App A keeps piping data to it. The fact that your App A was not dying before was likely just lucky chance. It would have been killed by the system eventually after going into the background.
I've developed an application to exchange small text messages between phones via Bluetooth.
My application works fine for 1 hour or 2 then it suddenly close without any warning both on screen or log-cat. During my tests I tried to exchange messages between 2 phones and I noticed that the applications silently close on them at different times and always without any reason
(I had both phones plugged to my laptop and with log-cat running).
Does Android shut down apps if it thinks that are idle? I send messages every 1-2 minutes.. shall I send them with an higher frequency?
EDIT:
I've noticed another strange behaviour.. sometimes when my app closes I lose all the messagges related to it into logcat.. they got completely wiped.
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.
I have written a simple database program in android. It runs fine, there is no force close error. But I checked from my application from Settings App I see the Force Close option enabled, which implies that my application is still running in the background, even though I have completely came out from my application to the home screen by pressing back key. And moreover I am not using any services, alarm or broadcast things.
Can some one please guide me what may be the probable reason?. Or is it okay? Or will it crash if I put it on device?
Can some one please guide me what may be the probable reason?. Or is it okay? Or will it crash if I put it on device?
Your application is alive until Android OS needs more memory and destroys it. What I have understood does Android start destroying activities before killing the whole application. This means that your application can be alive even if you have finished your activities.
Do not worry about this; Android OS is handling this extremely well.