Wednesday, 26 October 2016

Android interview questions and answers

1) Difference between main thread(UI thread) and worker thread?
People use the word "worker" when they mean a thread that does not own or interact with UI.  Threads that do handle UI are called "UI" threads. Usually, your main (primary) thread will be the thread that owns and manages UI. And then you start one or more worker threads that do specific tasks.

2) Difference between Service and Intent Service?
Service
IntentService
1)      The Service runs in background but it runs on the Main Thread of the application.
1)      The IntentService runs on a separate worker thread.
2)      The Service can be used in tasks with no UI, but shouldn't be too long. If you need to perform long tasks, you must use threads within Service.
2)  The IntentService can be used in long tasks usually with no communication to Main Thread. If communication is required, can use Main Thread handler or broadcast intents. Another case of use is when callbacks are needed (Intent triggered tasks)
3)      The Service is triggered by calling method startService().
3)  The IntentService is triggered using an Intent, it spawns a new worker thread and the method onHandleIntent() is called on this thread.
4)      The Service may be triggered from any thread, activity or other application component.

4) IntentService may be triggered from any thread, activity or other application component.

5)      The Service may block the Main Thread of the application
5) The IntentService cannot run tasks in parallel. Hence all the consecutive intents will go into the message queue for the worker thread and will execute sequentially.
6)       It is our responsibility to stop the service when its work is done, by calling stopSelf() or stopService().
6) The IntentService stops the service after all start requests have been handled, so you never have to call stopSelf().

3) Difference between Intent , sticky intent and pending intent?

Intent - is a message passing mechanism b/w components of android except for contentProviders
Sticky Intent - Sticks with android, for future broadcast listeners. sticky intent is a broadcast from sendStickyBroadCast() method, such that it floats arround even afyer broadcast, allowing others to collect data from it.
Pending intent - will be used when some one wants to fire an intent in future and may be at that ttime app is not alive.







7 comments:

  1. Outstanding blog post, I have marked your site so ideally I’ll see much more on this subject in the foreseeable future.
    java training in chennai | java training in bangalore


    java training in tambaram | java training in velachery

    ReplyDelete
  2. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me
    python training in chennai
    python training in chennai
    python training in Bangalore

    ReplyDelete
  3. Hello I am so delighted I found your blog, I really found you by mistake, while I was looking on Yahoo for something else, anyways I am here now and would just like to say thanks for a tremendous post. Please do keep up the great work.
    Blueprism training in Pune

    Blueprism training in Chennai

    ReplyDelete
  4. Good Post, I am a big believer in posting comments on sites to let the blog writers know that they ve added something advantageous to the world wide web.
    angularjs Training in chennai
    angularjs-Training in pune

    angularjs-Training in chennai

    angularjs Training in chennai

    angularjs-Training in tambaram

    ReplyDelete
  5. Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
    Microsoft Azure online training
    Selenium online training
    Java online training
    Python online training
    uipath online training

    ReplyDelete