Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Don't keep activities and Background processs limit. from a developer's perspective?

Tags:

android

I know that checking don't keep activities in developer options, makes android system kill the activity as soon as user leaves the screen - so a developer has to handle this by saving activity state by overriding onSaveInstance
But I don't understand the purpose of Background process limit. How does it affect the app? As a developer how should I handle the situation when I choose 'No Background Process'?

like image 836
Ashwin Avatar asked Oct 19 '22 01:10

Ashwin


1 Answers

This question is also very relevant to me. As a developer, you need to test edge cases and both "Do not keep activities" and "no background processes" options make your app behaves differently.

Here are what I've gathered about those options :

Do not keep activities : Activity is destroyed and recreated. Meaning you'll go through onCreate and onRestoreSaveInstance and so on. It's pretty much the same behavior as a change of configuration like rotating the screen. BUT : You do keep variables in memory.

Example : You have a User object, with a String name = "John" that you set when you log the user in. If you try to access user.getName() (and it was not saved in a Bundle) when activity is being recreated you will still get his name back.

No Background Processes : Does exactly the same as "Do not keep activities" PLUS clean up all variables.

Example : The user.getName() would this time returns null.

Bottom line : It would seem the most common scenario for user to run in is "Do not keep activities". But "no background processes" should also be tested as it could give different results and could I guess potentially happens (would be interested to have stats on this)

like image 168
user2230304 Avatar answered Oct 21 '22 04:10

user2230304