Release Note
ZenTalk


[Other] What does Force Stop and Clear Cache in Android actually do?

11975 1
Jump to specific floor
Latest Post
Hi Zenfone Fans,

Many of us might have faced situations when some apps does not work or crash repeatedly

                                             

Then we go to app info and force stop or clear cache of the app after which in most cases app works fine.

                                                 

But have you ever wondered what these options do and how they help app run fine on next instance. If you ever wondered, then here is a detailed look at what exactly happens.

>>  Force Stop

At the heart of Android is the Linux kernel, it is the component responsible for managing memory and processes along with a whole bunch of other resources. Whenever you start an app you are actually starting a Linux process.


A process is a logical container for a program (app). It is started by the kernel and is used as a way to share the system resources (including memory and CPU time) among all the running apps. Each process has an ID, known as the PID (Process ID); a priority - how important is it; its own address space, plus related pages of physical memory; and some state information: if running (or runnable), sleeping, stopped

The kernel’s job is to schedule CPU time and allocate memory to the process so that it can run. This juggling of processes goes on at the millisecond level, very fast. Finally, when an app exits, the kernel will clean up all the resources used by the app (like open files, allocated memory etc) and eventually delete the process that was created for that app.


Each app can be in one of several different states: running, paused or stopped. These are different to the process states, as defined by Linux, and represent the “Activity Lifecycle” as defined by Android. Google puts it like this, “as a user navigates through, out of, and back to your app, the Activity instances in your app transition through different states in their lifecycle.”


The interesting thing about Android is that it never kills an app directly. Instead, it kills the process in which the activity runs, destroying not only the activity but everything else running in the process, as well. It might do this when it needs to free up RAM or a user can kill a process by using Force Stop in the Application Manager.

                                             



When everything is working smoothly, an app will transition from one activity state to another and will either eventually be killed off by Android (after moving to the stopped state) or it will just hang around in the background until the user brings it to the foreground again. However if things start to go wrong the app can misbehave. It might stop responding to certain events, it might get stuck in some kind of loop or it might just start doing unpredictable things.


In such cases the app might need to be killed off and then restarted. That is what Force Stop is for, it basically kills off the Linux process for the app and cleans up the mess!


The reason why using Force Stop is recommended when trying to fix a misbehaving app it is 1) it kills of the current running instance of that app and 2) it means that the app will no longer be accessing any of its cache files, which leads us to step 2: Clear Cache.


>>  Clear Cache

After the app has been killed the next step is to delete the data in the cache directory. When a application needs a temporary file, a pre-processed file, or when it wants to keep a local copy of a file which was downloaded from the Internet then it will get placed in the app’s cache directory. Each app has its own directory where it can put working files.





The reason these are temporary files is that the app should not rely on these files being present as Android can delete them when a device runs low on storage. In these cases the app just simply downloads the data again, or processes the files again and creates new ones in its cache.


Apps can also store files more permanently by using the app data directory. This is different to the cache directory and is designed for persistent files owned by the app. Since Android is able to delete files in the cache directory without notifying the app, it is also safe for users to delete those files via the “Clear Cache” button!




This can help fix misbehaving apps as it clears out the pool of temporary files and forces the app to recreate them and so gives the app a kind of fresh start. This can often fix the problem as the error was in the processing of a temporary or cached file.


A side benefit of clearing the cache is that it frees up storage space. So if you are running low of internal storage then clearing the cached data for all apps can help.









I have added important excerpts. Read source for full test or watch video



Thank you for reading. Please comment for doubts and feedbackundefined
If you find this interesting, check out my other threads



Props
Last edited by ballerblocking01 on 2019/12/29 17:47

Thanks, I never knew what it was for. Just assumed it didn't make much of a difference and only used "force stop". Also as an app developer it's kinda embarsing not knowing what the differince was
Props
Advanced mode
You need to login first Login | Register Now

Points policy of this forum

wishes

Archiver|Mobile ver.|

Fast reply Top Return to list
Share link list
Share by pm