Android app Vs. Handle

I created an Android application with one name Activity and package "com.explore"

  <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> 

I am running the ps command.

 USER PID PPID VSIZE RSS WCHAN PC NAME app_137 2974 91 478604 48524 ffffffff 00000000 S com.explore 

I press the button. I exit the application and go to the main screen. Now run the ps command again.

 USER PID PPID VSIZE RSS WCHAN PC NAME app_137 2974 91 472428 42572 ffffffff 00000000 S com.explore 

Process 2974 is still running. Can someone explain me the behavior? Is it memory usage, state, or how long will the process last? Should I kill a process from my code after clicking? How to gracefully kill a process?

+4
source share
2 answers

When the application starts, if it is not already running, it receives a new process identifier. This identifier stays with it until it is no longer in memory. (This can be achieved and verified using the "Force Stop" option in the application settings.)

However, when the user clicks the Back or Home buttons, the application does not exit and in most cases stops or stops.

You can read this documentation , which details the process life cycle. Points 1 and 2 basically say that the foreground process (or one after something superficial, such as dialogue) will not be stopped if it is not absolutely necessary (power is close or there is no memory). Point 3 is important; he says that any process that is no longer needed, i.e. the user "closed" it - it may or may not be killed, depending on the device’s memory. And finally, paragraph 4, everything that does nothing, but just .. existing .. will be killed as soon as possible.

You can also watch the Activity life cycle . This will show you exactly when each of the application steps will be executed (that is, when it is paused, when it will stop and when it will be destroyed). The only thing it does not apply to is the reallocation of memory (or orientation changes that repeat the entire life cycle).

In conclusion, remember that Android is smart. He manages his processes better than most developers, and tries to save as many processes as possible for easy reuse. Unless you are absolutely sure that you want your process to be out of memory, you should never kill it. And the way we must kill and control processes is never good .

+5
source

Start reading fundamentals . In short, in most cases you do not have to worry about processes; Android takes care to automatically start and stop them. The killing process can lead to a restart of the system, therefore, as a rule, not so much. Forget about the "task killers" and similar utilities, which they are currently mostly useless.

+2
source

Source: https://habr.com/ru/post/1433289/


All Articles