AdSense

Saturday, 5 November 2016

Lifesaver – Android collections of Questions and Answers

Lifesaver – Android collections of Questions and Answers

There are usually few instances when we need a collection of questions and also need their answers:
  1. When we are about to take some interviews
  2. When we are about to be interviewed
  3. Sometimes, it is only for quick knowledge gain too,

Never the less, having a collection is so helpful, a lifesaver. Here we are sharing some set of questions and answers for Android.

1.    What are strategies for handling different screen sizes?
a.     Nine patch images
b.    Different resources for different screen sizes - You can have different images, layouts, etc. for each type of screen
c.     dp – device independent pixels.  An abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
d.    sp  - Scale-independent Pixels. This is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

2.    How does a nine patch image differ from a regular bitmap? A nine patch image is a normal PNG file (*.png) with an empty one-pixel border added around the image. You draw the stretchable patches and content area. This helps prevents image distortion.
  1. What is the difference between a ViewGroup/Layout and a View? A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers. This class also defines the ViewGroup.LayoutParams class which serves as the base class for layouts parameters
  2. What types of layouts exist?
a.     LinearLayout - A Layout that arranges its children in a single column or a single row. The direction of the row can be set by setting the orientation.
b.    FrameLayout - FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.
c.     RelativeLayout - A Layout where the positions of the children can be described in relation to each other or to the parent.
d.    AbsoluteLayout - A layout that lets you specify exact locations (x/y coordinates) of its children. Absolute layouts are less flexible and harder to maintain than other types of layouts without absolute positioning.
  1. What layout do you proffer and why? A LinearLayout is the easiest and can be used for most purposes
  2. What is a SurfaceView? Provides a dedicated drawing surface embedded in the view hierarchy.
  3. What is an adapter? An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.
  4. What are some types of adapters?
9.    How would you handle long running processes? Learn more here: http://developer.android.com/resources/articles/painless-threading.html
  1. What different ways can you persist information
a.     Application Preferences
b.    Files
c.     Content Provider
d.    SQLite DB
  1. What reason would you have to create a content provider as opposed to using SQLlite directly?
    You can allow other apps access information via content provider.
  2. What is the manifest? What kinds of things are stored in the manifest? Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application's code. Among other things, the manifest does the following:
a.     It names the Java package for the application. The package name serves as a unique identifier for the application.
b.    It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities (for example, which Intent messages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched.
c.     It determines which processes will host application components.
d.    It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
e.    It also declares the permissions that others are required to have in order to interact with the application's components.
f.     It lists the Instrumentation classes that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they're removed before the application is published.
g.    It declares the minimum level of the Android API that the application requires.
h.    It lists the libraries that the application must be linked against.
13.  How do you get location? Android gives your applications access to the location services supported by the device through the classes in the android.location package. The central component of the location framework is the LocationManager system service, which provides APIs to determine location and bearing of the underlying device (if available).
  1. What is an activity and lifecycle ?
    android lifecycle - babagyan.com
    android lifecycle

  2. How does that R.java file get generated?
    Once you provide a resource in your application (discussed in Providing Resources, you can apply it by referencing its resource ID. All resource IDs are defined in your project's R class, which the aapt tool automatically generates.When your application is compiled, aapt generates the R class, which contains resource IDs for all the resources in yourres/ directory. For each type of resource, there is an R subclass (for example,R.drawable for all drawable resources) and for each resource of that type, there is a static integer (for example,R.drawable.icon). This integer is the resource ID that you can use to retrieve your resource.
16.  Why create a Handler?
A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it – from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.
There are two main uses for a Handler: (1) to schedule messages and runnables to be executed as some point in the future; and (2) to enqueue an action to be performed on a different thread than your own.
  1. What is the AsyncTask object used for?  Why should you only change ui objects in the OnPostExecute function. 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.
    An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute.
    You should only access ui in the onPostExecute and onPreExecute because at that point you are running on the UI thread.