Why does Android "kills" backgrounds apps? What can you do about it? - android

I'm only on search for the reason why Android does this and what can you do to "stop" it or handle it when coding any app. I haven't found any info about this except some yt videos that teach you how to stop it when using your Android smartphone. I'm looking for documentation or something like that to read and learn why does this happen and how to handle it.
Sorry for my bad english, not native. Thank you.

Why? Because a device is a computer and therefore the limited resources should be optimized. The optimizations favors the app with the user is interacting, making the user experience fluid.
How this happen and how to handle it is the life cycle
And how to make things even if the app is not open it is about the workmanager

From the official documentation
It is important that application developers understand how different application components (in particular Activity, Service, and BroadcastReceiver) impact the lifetime of the application's process. Not using these components correctly can result in the system killing the application's process while it is doing important work.
and how it happens :
To determine which processes should be killed when low on memory, Android places each process into an "importance hierarchy" based on the components running in them and the state of those components

Related

Android: How to create an unrestricted background service, beyond APK permissions?

I'd like to create a Java/Kotlin background service that is not afflicted by resource management limitations at all.
I know that this is pretty much contradicting Android design principles, and I am pretty sure this is not possible for a normal app.
But having full root permissions, what would be the cleanest way to build/install such a service? I would still like to use Android Studio to develop, and benefit from Java API portability.
Edit: It turned out that my question has been misleading. I am not targetting an existing Android HW Device, where a user has to grant permissions, but rather a custom AOSP installation, which i have full control of. I already figured out that I probably have to write a system service for this. However, I will accept the given answer for the general case as reference for others.
You can try using this approach and ask your user to add your application to the white list. Any app that is there won't be a subject of system resource management regarding the Doze mode; thus, the system won't kill your service while it's in background while you don't break the other limitations such as max amount of available memory.
Or you can just show an alert and ask the user to add your application to the white list manually.

Should an android app close its service when exit if there's nothing to do

Some apps in my phone(android) leave one or more services after I close them (using back key and clearing recent app), because I can see them in my Settings->Apps->running tab. Some of these apps obviously don't need to have a service running in the background when they're not being opened because they actually don't need to do anything when it's closed, at least no reason I can think of. Can these kind of apps be considered as "bad" app? Or if there's some reason for this since I find it relatively common.
You right
I prepared a presentation on this topic and i found this is worst mistake ever done by developer.
Leaving a service running when it’s not needed is one of the worst
memory-management mistakes an Android app can make. So don’t be greedy
by keeping a service for your app running. Not only will it increase
the risk of your app performing poorly due to RAM constraints, but
users will discover such misbehaving apps and uninstall them.
I found very much about this topic here https://developer.android.com/training/articles/memory.html

How to properly monitor and log Android OS events/activity in the background

I would like to know the correct way to monitor system events and operating system activity in Android. My research so far indicates there are various methods for running Activities, Services, BroadCastReceivers, etc. but I don't have an overall comprehensive answer for everything I want to accomplish yet. I did come across an app today called "Carrier IQ" and was wondering how they do it. I believe their app is built into the kernel or at least the phone's OS image, something I want to avoid doing if at all possible.
I know that the Android SDK offers various ways to obtain
Since my app cannot be allowed to be suspended, should it run as a foreground service? If I do this, will I consume too many resources if I need to poll for various activity? I ask this because I don't think I can get everything through receiving events (i.e., using a BroadCastReceiver). I think I need a combination of polling and events.
I want to log sensors, events, OS activity, etc. for a user study. This is NOT for hacking or phishing purposes!
These are the top three projects that I think may accomplish something similar to what I want to achieve, but I have not yet determined if they are viable solutions:
android-hci-extractor
cellbots data logger
android-os-monitor
Does the Android manifest permissions list contain all of the permissions your app will need?
http://developer.android.com/reference/android/Manifest.permission.html
Then you can just ask for permissions when the app is installed and you should be able to access them.

Android - How to make my application not to be garbage collected ever?

I am developing one sample application.
I want this application should not be garbage collected ever until i switch off the phone.
1. Is this is possible in android?
2. If it is possible. How can i do this?
No, it's not possible in Android. And there is a good reason for it : system manages memory as a limited resource and no application can remain active if not used to ensure memory is available to other apps.
Nevertheless, technically, you can use a foreground service to ask the system to keep your application running as long as possible, possibly longer than a "normal" app with no such a service.
But, all in all, what you want to achieve is not a good idea. The Android way is to create your app, persist its state and re-set new instances of your app in the same state. For persisting state there are multiple solutions like using SharedPreferences, files or a database.

Android Code Injection

Creation of a hidden process seems to be impossible ... so i came to conclusion that hiding a process from the user is impossible so if the service or process appears to RUN as a sub process to any other applications like PHONE APP , or MESSAGING APP , the running process can be hidden to an extend .
This can be only achieved by code injection , so want a help in achieving this . code injection from the user level.
Sure this is possible - http://www.phrack.org/issues.html?issue=68&id=6#article. And as for #commonswear's answer, that's completely wrong. Many respectable developers do this type of this for good, in fact some rooting techniques work this way. Also, sometimes developers can do this to their own code post-deployment, and some developers may do this and notify the user because it provides extra functionality that they wanted in the first place.
Fortunately, this is impossible, short of a security flaw as #Dave notes.
No respectable developer tries to hide processes from users or inject code into foreign processes, as seems to be your intent.

Categories

Resources