farhanjk
farhanjk

Reputation: 1762

Why don't Android and iOS kill the process when the app is closed?

On Windows, MacOS and Linux, when an app is closed, the norm is that its process is also killed. This happens as default on Windows/ Linux, and on MacOS, it still seems like a good idea to press CMD+Q to kill the process when no app window is open.

On Android (and iOS too) when the app is backgrounded, its process still keeps living in the memory till the OS finds it necessary to push it out. The process can be killed but this step is not the default OS behaviour and is somewhat discouraged by the UX.

Why?


Update

Some of the replies do seem to suggest that there are potential benefits in keeping the app in memory. So a further follow up will be, why then main stream desktop OS(es) do not follow the same approach to reap all the same benefits?

Upvotes: 1

Views: 908

Answers (4)

Perraco
Perraco

Reputation: 17380

Answering to your question update and agreeing with the already posted answers stating that keeping an app in memory may be better for battery and app resume/start up.

A mobile device is designed to be fully mobile, to be in your pocket or hand all the time, and connected to an electricity outlet just for charging, and usually nothing more. So, it must have a battery saving centric design.

A desktop is always connected to an outlet, so doesn't have the battery shortcomings and requirements of mobile devices.

About laptops, although they are portable, they are actually used most of the time also connected to an electricity outlet. The fact that they can be carried from one point to another doesn't make them comparable to mobile devices.

So, although desktop OS(s) now days have battery saving features tailored mostly for laptops, their design is focused with the fact that the host device will usually work connected to an electricity outlet, and they have never evolved to have a battery saving centric design, which is a "must have" requirement for mobile devices.

On the other hand, if you want to consider not the battery but the app resume/start up benefits, then actually such feature is already implemented in both types of OS(s), but in a very different way. For example in Windows you can minimize a program, this is the exact same thing as pressing the home button in Android. To close it you press the x button a the corner or the program's exit option, that would be like going to Android apps task manager (recent apps history) and killing the app.

Upvotes: 2

Ufkoku
Ufkoku

Reputation: 2638

According to documentation, there are 4 states of application process in android app.

Let's look at a few cases.

1. App has running Activity. User presses home button.
In this case app status will be moved from Foreground to Cached.
Cached state is used for providing better UX, when user switches between apps. Because opening a cached activity is much faster then restoring it from saved state.

2. App has running Activity and Service. User presses home button.
In this case app status will be moved from Foreground to Service.
Service state is used for processes which have some unimportant background job. In this case process is kept, because it has some background job to do. Of course you can move your Service to a separate process, but it is not a default behavior.

3. App has running Activity and foreground Service. User presses home button.
In this case app status will be moved from Foreground to Visible.
Visible state is used for processes, which are visible to user, but he doesn't interact with it directly. Foreground Service is used for doing important background job and keeps process at Visible state. Again UI and Background parts of app by default are placed in same process.

Upvotes: 0

Fran Bolado
Fran Bolado

Reputation: 415

Android is very good at managing its resources. It has a certain amount of memory (RAM) to work with, and it’ll happily allow apps to use as much as they need for best performance.

If RAM starts to get a bit short, and other apps and tasks need some, then the OS will quietly close one of the apps running in the background that you haven’t used for a while, and assign that app’s RAM to the new task.

As a result, apps can stay in memory for hours, days or potentially even weeks since you last used them. And this is fine. They’re not draining the battery or using other resources so there’s no downside; the upside is they will load much quicker when you need them, and load them right back to the place where you left off too.

(It’s also worth noting at this point that there’s really no benefit in keeping RAM free. RAM exists to be used, and using all of it at any given time—or virtually all of it at least—will ensure your phone or tablet runs smoother than if you try and keep some RAM free.)

With all this in mind, it becomes clear why closing apps can have a worse effect on Android than leaving them open.

Ref: androidtipsandhacks.com

Upvotes: 3

Acemond
Acemond

Reputation: 86

Because some applications behavior relies on background services that can not work if the main process is killed. When you swipe off an application from the recents, you're not really killing the app, the background services are still there.

Imagine that you close Whatsapp and the OS thinks that it's a good idea to kill the entire process. You wouldn't recieve any message unless you re-launch the app.

Upvotes: 0

Related Questions