Saturday, January 24, 2015

Experienced Android Interview Questions - 3

Company - provab

1. why to extend application class, how to access common variables in all activities? What is the use of Application class?
There are two contexts in Android.
1. Activity level context
2. Application level context

Application level context will be created while creating your application. There will be only one application context shared for all the components of your application.
So if you want to share some temporary variables with all the components of your application, then create your own class which extends Application class. Use setters and getters to share some variables in that class.

Note: Make sure that you give android:name as your class which extended Application class,in the <application .. >tab of manifest file.

The other uses of Application class is, if you want to do some task before loading your first activity, then write it in Application class's onCreate() method. Application class also has some useful methods which will get triggered in case of low memory, which you can use to check if your app is running on low memory to alert user.

2. what is viewholder?
ViewHolder is a technique used in Adapter's getView() method,
to reduce the no of findViewById() calls.
Adapters are intelligent enough to reuse the old views while user scrolls throught the adapter view elements. Programmer should check if convertView is not null, then reuse it rather than creating a new view for that row.
Apart from this we can optimize it more by reducing number of findViewById() calls by moving all those into ViewHolder class.
Programmer can also move some reusable components like arrays or database query results also into ViewHolder to avoid unncessery function calls.


3. what is beanclass?
A bean class is a plain old java class, which has
1. no argument constructor
2. all its fields as private with setters and getters
3. and implements Serializable.

Basically bean class can be used as an object which itself can hold other states and objects.
It implements serializable enabling the programmer to transfer it out of java memory, like into some streams, or hard disk, or database, or to some network. It enable java programmer to not loose an objects state while transferring into streams.

4. what is offline synchronization?
5. Do you know how to do facebook integration?
6. how will you create camera view to take picture with out intent and camera button?
7. how to upload apps to play store?
8. I have a list view with 100 items. But I want to show only 10 items initially and when I scroll down or up, then only I want to display the items dynamically. How to do it?
9. Why java allows only one public class in a given file?
10. If I close the application, will it destroy all the static variables?
Don't rely on static variables, because static variables may not be cleand properly on the application exit. 
Static variables will be created when the class containing them is loaded first or used first. They will be destroyed once JVM unloads that class from the memory.
But Android has a concept of empty process, which says your app may not be removed from the memory if it is frequently used by user, in which case your static variables will not be cleard of completely.
Better to rely on Application class which will be created properly on application startup time and will be cleard of once user exits app. This is the best way to share some temporary variables between the components.

Note: Static variables are considered as anti-design of android apps from ages.

Still if you want to rely on static variables due to some reasons, then try to understand what is the scope of that variable and try to initialize some null values to it on shutting down the last component which is accessing that variable. But again it is a complicated logic.

11. How to access variables globally, in all the activities of an application?

12. In MVC architecture, where is database stored?
In MVC (Model-View-Controller) architecture Model will interact with Database part.

13.How to handle when GPRS is not available while registering any form.(store or update data)
14. While running application if any call comes how to handle and which method is called?
15. Can we call SQLiteOpenHelper class from onStop() method of Activity?
16. How AsyncTask is useful? How it is different from normal thread?
17. How will you detect the exit of an application in android?
18. How to close all the components of an application and exit the application?

No comments:

Post a Comment