Select chapter



basics (6.papers)
activities (5.papers)
services (2.papers)
threads (2.papers)
receivers (1.papers)
advanced android (2.papers)
SQLite database (1.papers)
adapters (1.papers)
adb and ddms (1.papers)
widgets (1.papers)
fragments (1.papers)
UI (1.papers)
Hide

Sponsored Links


  

android interview questions and answers

1
Android supports
  1. MultiThreading
  2. Multi threading and multi tasking
  3. single threading with multi tasking
  4. single task with multi threading
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
3
How to stop a thread in android?
  1. Use stop() method of the Thread class.
  2. Use a volatile boolean flag, based on which return from the run() method of the Thread.
  3. use exit() method in run() method to exit and stop the thread.
  4. none
Show Answer
Share Facebook gmail Twitter
4
What is a thread?Is service with Thread possible?
  1. A thread, in the context of Java, is the path followed when executing a program. All Java programs have at least one thread, known as the main thread.
    Service with thread is not possible.
  2. Thread is a dispatch able unit to the CPU.All Java programs have at least one thread, known as the main thread.
    Service with thread is not possible.
  3. Thread is a dispatch able unit to the CPU.All Java programs have at least one thread, known as the main thread.
    Yes Service with thread is possible. But by default service will run in main thread.
  4. None are correct
Show Answer
Share Facebook gmail Twitter
5
Define AsyncTask?How many methods are there and how parameters work in it?
  1. The AsyncTask class provides a thread that will always run in background. It also supports reporting progress of the running tasks.
    
    There are four methods in Async Task:
    1. onCreateTask()
    2. doResumeTask()
    3. onStopTask()
    4. onDestroy()
    
    The three types of parameters in AsyncTask:
    
    1. Params: the type of the parameters sent to the task upon execution.
    2. Progress: the type of the progress units published during the background computation.
    3. Result: the type of the result of the background computation.
  2. The AsyncTask class is a way to achieve multithreading in android application, where multiple tasks can be run at a time. It synchronizes with the main thread. It also supports reporting progress of the running tasks.
    
    There are four methods in Async Task:
    1. onPreExecute()
    2. doInBackground()
    3. onUpdateProgress()
    4. onPostExecute()
    
    The three types of parameters in AsyncTask:
    
    1. Params: the type of the parameters sent to the task upon execution.
    2. Progress: the type of the progress units published during the background computation.
    3. Result: the type of the result of the background computation.
  3. AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
    
    There are four methods in Async Task:
    1. onCreate()
    2. onResume()
    3. onStop()
    4. onDestroy()
    
    The three types of parameters in AsyncTask:
    
    1. Params: the type of the parameters sent to the task upon execution.
    2. Progress: the type of the progress units published during the background computation.
    3. Result: the type of the result of the background computation.
  4. None are correct
Show Answer
Share Facebook gmail Twitter
6
How to kill a thread?
  1. <theradobject>.stop();
  2. Thread.stop();
  3. return from run() function
  4. <threadobject>.kill()
Show Answer
Share Facebook gmail Twitter
7
Why android follows single threaded UI model?
  1. Because other threads should not manipulate UI.
  2. Because synchronization is costly compared to single threaded model.
  3. Because synchronization is not possible on UI.
  4. Because UI thread only can access UI.
Show Answer
Share Facebook gmail Twitter
8
If I create a thread in my Activity and close my activity, will that thread run in the back ground or will be killed automatically on activity close? If it keeps running in the back ground, when will it be killed?
  1. that thread will run for ever, if there is no condition in run() method to return and close it.
  2. that thread will killed immediately on activity closure by android.
  3. either it may run for ever if there is no condition in run() method to return, or it may be killed by android in case of low memory scenario.
  4. option 3 is right, and it is highly unpredictable how it behaves. this kind of design is wrong. if you want a thread in activity, make sure that either you kill before leaving activity, or put a condition to close it in run method, or better to start a service with thread.
Show Answer
Share Facebook gmail Twitter
9
Is it possible to start asynctask from background thread?
  1. Yes we can start asynctask from any where.
  2. it is not mandatory to start asynctask from worker thread, but it will not give any problem even if we do so.
  3. it is mandatory that one has to call asynctask only from main thread, else it may crash at run time when we try to touch UI from onPreExecute [or] onProgressUpdate [or] onPostExecute functions.
  4. no, we should not start from other threads, it gives compile time error.
Show Answer
Share Facebook gmail Twitter
10
what will happen if execute() function of asynctask is called more than once, for a give asynctask object?
  1. it will create one more thread / asynctask object.
  2. there is no effect on it because already it has created an asynctask on first execution.
  3. we should not call execute more than once on one object, it will throw run time exception.
  4. it gives compile time error if we try to do so.
Show Answer
Share Facebook gmail Twitter
11
how many threads will be created with asynctask?
  1. asynctask is used to do multi threaded programming, so it creates multiple threads.
  2. it creates only single thread, no matter how many objects you created for asynctask class.
  3. till donut - it is used to create single thread, from 1.6 to 2.3 - it is used to create multi threads, from 3.0 on wards - it is again used to create single thread.
  4. it won't create any thread.
Show Answer
Share Facebook gmail Twitter
12
How to create a service with single thread? should I use IntentService or AsyncTask?
  1. Use IntentService, if you don't want to interact with UI.
  2. Use AsyncTask if you want to interact with UI.
  3. both option 1 and option 2 are correct.
  4. none
Show Answer
Share Facebook gmail Twitter
13
In which thread asynctask functions will execute?
  1. all four functions executes in worker thread context.
  2. all four functions executes in main thread context.
  3. onPreExecute, onProgressUpdate, onPostExecute - runs in background thread, doInBackGround - runs in MainThread.
  4. onPreExecute, onProgressUpdate, onPostExecute - runs in Main thread, doInBackGround - runs in background Thread.
Show Answer
Share Facebook gmail Twitter
14
Do all components of an android application run in same thread?
  1. it is based on number of components in that application.
  2. option 1 is true, because activity, service, receiver, and content provider will create a thread by default internally.
  3. each application will have one process and one main thread created by system, by default.
  4. process or application by default will not have any thread.
Show Answer
Share Facebook gmail Twitter
Read more papers :