I am writing this question not as part of any specific application, but as part of potential use for future applications. I know that the answers to this question can be very application specific, but I hope you will bear with me. I will convey my understanding as is, and hopefully you can help me by extending it. Surprisingly in vain, I have searched the web for a 'complete' overview and have not been able to find it. Any links to relevant pages are welcome obviously.
An android application by default runs in a single process. Each Activity or Service that you start will by default even run in the main thread. All actions by the user are queued by the Looper of the main thread, and the respective callbacks are handled in the main thread.
In order to provide concurrency, threads can be started in lots of different ways, single or in pools. There is not explicit need in this regard for multiple processes. Using multiple processes to allow the multiple cores of your device to work in parallel is not necessary since Threads can be run in parallel as well, maybe even your main thread? But perhaps it will be easier to actually achieve?
In order to let an Activity or Service work in a specific (potentially different) process you only set the android:process
attribute in the Manifest file. So easy to implement?
The Android framework is specifically built for mobile devices, which typically have limited memory to go around with. Therefore processes can be killed under a variety of circumstances, clearly stated here. As long as you implement the lifecycle callbacks of Activities and Services, such as onStop
or onDestroy
, this should not give any real problems. But obviously compartmentalizing pieces of your application, by using multiple processes, could potentially keep more important things alive. For instance a background download Service could be kept alive (level 3 in importance), while the process with the initial Activity that started this Service, now in the background (level 4) could be freed for its resources. Furthermore the fact that you are isolating core features of your application might allow your device to make better use of its resources?
The Binder framework makes IPC fairly easy to handle, and is something you will use generally, regardless of actually using multiple processes. I think the main cost of having multiple processes to the application is the access to shared resources, or the sending of those resources between processes, excluding the additional resources required for forking a process from the Zygote. I wonder whether using multiple processes will actually force you to implement your application differently?
I think that conceptually the use of multiple processes will not increase ease of implementation?
To summarize the pros of multiple processes:
Cons:
The main use case I can think of:
If you have any remarks on my understanding please state so (Note several question marks in my explanation). If you have any pros and/or cons to add please reply as well, I will add them to the list.
While you might never have to build a multi-process app, it's possible to have an Android app with components running in different processes. You get several benefits like more memory, performance improvement (depends on implementation) and more by going multi-process.
Android devices are multiprocessor systems that can run multiple operations simultaneously, but it is up to each application to ensure that operations can be partitioned and executed concurrently to optimize application performance.
You should already know by now that Android is based on Linux. As such, each application runs in its own process (with a unique PID): this allows the app to live in an isolated environment, where it cannot be hindered by other applications/processes.
The short question is: Android might decide to shut down a process at some point, when memory is low and required by other processes that are more immediately serving the user. Application components running in the process that's killed are consequently destroyed.
Communication: As multiple processors are communicating with each other so the operating system implementation is complex to handle. More memory required: As there are multiprocessors working with each other so each processor needs memory space.
Top 5 Disadvantages of an Android Smartphone. 1 1. Hardware Quality is Mixed. You may think "the more the merrier" when it comes to choices; however, it may cost you a lot to find a compact and ... 2 2. You Need a Google Account. 3 3. Updates Are Patchy. 4 4. Many Ads in Apps. 5 5. They Have Bloatware.
Some are for grabbing info quickly; others offer convenient controls, such as for your media apps. Although iOS smartphones have widgets, Android's are a lot more complex and capable. They allow you to access important information with the least amount of scrolling and tapping. 5. Diverse Phone Options
Less electricity usage: In a single processor system, there is more load as many processes have to be executed at a time. But in multiprocessor system execution of multiple processes in done in a few times.
Using multiple processes to allow the multiple cores of your device to work in parallel is not necessary since Threads can be run in parallel as well, maybe even your main thread?
Live (non-blocked) threads will be run in parallel across multiple cores automatically.
But perhaps it will be easier to actually achieve?
I would consider threads easier than processes, but "easier" is generally an opinion.
For instance a background download Service could be kept alive (level 3 in importance), while the process with the initial Activity that started this Service, now in the background (level 4) could be freed for its resources.
Except that you wasted more resources by having the two processes in the first place, and keeping a service running for long periods of time is generally an anti-pattern.
The Binder framework makes IPC fairly easy to handle, and is something you will use generally, regardless of actually using multiple processes
Developers do not normally use Binder directly. Only those implementing bound services need it, and that is a fairly small percentage of Android apps.
I wonder whether using multiple processes will actually force you to implement your application differently?
Yes.
Isolation potentially gives more lifetime protection
IMHO, this is not a valid excuse for wasting RAM, CPU, and battery on multiple processes.
Parallelization performance boost?
Threads cover this.
The main use case I can think of
While there may be scenarios in which your use case actually is a net benefit to the user, it is far from certain. Given that you have to implement your app differently to handle multiple processes, using multiple processes is a last resort approach, not the sort of thing that you do routinely, IMHO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With