Answer: B True, always any given application will have default one main thread.
Description: Default android will allocate one main thread called as (UI thread) to every process or application.
Answer: ANR - will occur if we are doing any other heavy functionality along with UI in single Main Thread.If two heavy functionalities happen in single thread, it will delay response to user actions, which may irritate user, and hence stop your process.
Solution - Run only UI components in Main Thread.
Description:
Answer: A One process, one Thread, Yes it is possible to run in more than one process.
Description: Before loading an application into RAM, a process will be created with a thread by default. Even though in Linux, an application will be given only one process to run all its components, it is quite possible that components of a given application can run in more than one process provided both processes have same Linux user id.
Answer: D option 2 is correct, it is also possible with HandlerThread to have inter-thread communication.
Description: if thread-a wants to send a message to thread-b, then thread-b's looper should be prepared to retrieve message send by others.it is also possible with HandlerThread to have inter-thread communication.
Answer: C Request Main Thread through inter thread communication using Handlers or runOnUiThread() function, and manipulate ui
Description: All Ui controls or views will be under control of Main thread (UI thread). If other thread wants to touch UI, it is possible through one of the inter thread communication, that is through handlers or through runOnUiThread() function or through asynctask.
Answer: C Both option1 and 2 are right
Description: If you want a service with one thread, then go for IntentService, or a normal service with a thread in onCreate().
onCreate will be called only once, so if you create a thread there, then it will become a service with single thread..
But make sure that from onStartCommand you are queuing up the requests to that thread using some handlers.
Even if you use IntentService also, that will also create only one thread in that service. Using IntentService is a good option to go for a service with single thread.
Answer: C 1 main thread created by android system
Description: Since every process requires a thread to run with CPU, by default android system will create one main thread for every application.
Answer: D option 3 is right, along with that there is one more way to start a new task by using FLAG_NEW_TASK when you are starting a new activity.
Description: Android supports multitasking at app level also. That means you can create apps with multitasking capability. One way to achieve multitasking is press home button on current task which will move it to background and then you can start new task from launcher.Another way is use FLAG_NEW_TASK in the intent, when you are starting a new activity.
Note: User can press and hold home button to see all the starting activities of recent tasks he has visited. From there also user can switch to other tasks by selecting any of those activities.
Answer: A Yes it supports both multi tasking and multi threading.
Description: Yes it supports both multitasking and multi-threading. User can launch multiple applications at a time and can switch between those applications (this is called as multitasking). In a given application we can have multiple threads which can run simultaneously (this is called as multi-threading).
Answer: D can use any of above mechanisms, but using serialization in android is not suggestible because it delays IPC mechanism.
Description: IPC means Inter process communication : Where two applications or processes will communicate with each other by passing some data between them.
Since android is meant for embedded and small devices, we should not use serialization for IPC, rather we can use BINDERs which internally uses parcels. parcel is a sort of light weight serialization by using shared memory concept.
There are many differences between Binder IPC and Serialization IPC:
1. Serialization is very heavy to use in embedded devices, communication will be very slow.
2. Binders uses Parcels to make IPC very fast.
3. Binders internally uses Shared memory concept which uses less memory while sharing data between two processes.
Bottom line : Binders uses less memory, and quite fast as it uses parcels. Serialization is very heavy , takes time to send and receive data, and also it takes more memory compared to binders.
Note : To pass data between activities, services, and receivers use only Bundles. Don't go for either serialization or binders.
Binders are specifically used only for binder services where 2 processes will communicate.
Answer: A Binder uses shared memory concept to do Inter process communication
Description: Serialization and Binders are both IPC mechanisms how to processes will communicate. Serialization is very heavy as it has to copy hole data and transmit to other process through channel. But Binders are light weight where both the processes will share or communicate the data using a shared memory concept. what ever the data has to be shared it will be kept in a common shared memory and both process's can access that memory to make communication faster.
Answer: C option 2 is right, but other thread can touch UI through handlers [or] runOnUIThread() methods.
Description: Android follows single threaded UI model, so other threads can't touch UI. but other thread can touch UI through handlers [or] runOnUIThread() methods
Answer: D Option 3 is right, with out handler threads also one can achieve with normal threads if programmer prepares its looper programmatically.
Description: Inter thread communication : means passing some data between threads.
Every thread internally will have 2 components: Looper & Message queue.
Message Queue : is to store incoming messages
Looper : will keep checking message queue to respond to those messages.
With out Looper, it is not possible to achieve Inter thread communication.
Only Handler Threads will have loopers.
Normal Java threads will also have loopers but they will be in the passive mode. (Since looper is passive it cannot check message queue for new incoming message).
Since your looper is not active in java threads so they cannot handle inter thread communication.
You can enable the looper by calling looper.prepare().
So, Inter thread communication is possible through only Handler Threads. Because Handler threads allows message passing mechanism through loopers.
There is one more technique to have Inter thread communication.
Share some data in some common storage, and allow both the threads to access that data by using some synchronization mechanism like wait, notify.
This is possible with normal java threads also.
Answer: B Handler thread will have looper and MessageQueue, but looper is prepared to handle incoming messages.
Description: Handler thread is extended version of thread, where its looper will be prepared to handle incoming messages from other threads (Inter thread communication). But for normal java threads, looper will be there but in passive mode, i.e not prepared for inter thread communication.
Answer: A it will be alive, but its priority will be least compared to thread in a service.
Description: once a thread is created, it will run independently of who has created until the work given to that thread is finished. but in case of low memory scenarios a thread created by activity and which is running in the background will have more susceptibility of being killed by android system. More worse is android can not recreate the thread which was killed because of low memory. but if that thread was in service, then chances of getting killed by android due to low memory may be less than previous situation. even if android system kills the thread, again it will start the service when memory resources are available and service can re-initiate that killed thread.
Answer: B process and application are same. Task may contain 1 or more applications. thread is an internal part of a process created by OS.
Description: Process - every instance of an application being executed is called as process. You execute same application two times, it will create 2 processes.
Application - is generalized term of a process.
Task - can have one or more applications in it.
eg: task of sending a message : we will start with message application, lets say i want to attach a photo to my message, then i will open gallery application also. In this case my task has got two applications, messaging and gallery application.
Thread - theoretically thread is a light weight process, or part of process.Practically thread is dispatch-able unit to CPU, and it is internal part of a process. With out a thread in your program it is difficult to execute your application.application. That's why by default every process will have at least one thread created by Operating system.
Answer: D both option 1 and 2 is right.
Description: to avoid synchronized problems with multi threaded programs, use synchronized block or synchronized methods, which ever suits better.
Answer: B i & ii
Description: syn method - all statements in this are synchronized. if already any thread is holding lock on this function's object then other threads can't call another synchronized method on same object.
syn block - only this block of code is synchronized, not whole method. If a function is having 1000 lines and I access shared data only in 5th ,and 6th line, then better to put syn block than making whole function as synchronized.
Answer: B Looper - part of any Thread to loop through message queue.
Message Q - part of any thread, will store incoming messages to this thread.
Handler - communication channel between two threads.
Description: Looper - part of any Thread to loop through message queue.This will be used to check if any incoming message has arrived to this thread. Only one looper exists for a given thread. Only for handler threads this looper will be activated, for other normal threads this will be in passive or inactive mode.
Message Q - part of any thread, will store incoming messages to this thread. For any thread only one message Q is available.
Handler - communication channel between two threads. Handler is associated with Looper. for a given looper we can n number of handlers to communicate with it from out side world.
Answer: D only handler threads will have loopers, but we can prepare normal threads looper also.
Description: Main Thread is a handler thread, so it will have looper enabled. Normal threads looper will be in disabled mode, where as handler threads will have their loopers enabled. but if we want we can prepare loopers for normal threads also.