Posts

Showing posts from 2012

Units used for Measurement in Android

Dimension A dimension value defined in XML. A dimension is specified with a number followed by a unit of measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android: dp Density-independent Pixels - An abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal to 1px. When running on a higher density screen, the number of pixels used to draw 1dp is scaled up by a factor appropriate for the screen's dpi. Likewise, when on a lower density screen, the number of pixels used for 1dp is scaled down. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Using dp units (instead of px units) is a simple solution to making the view dimensions in your layout resize properly for different screen densities. In other words, it provides consistency for the real-world sizes of your UI elements across diffe

All about Context

Context Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system.  It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc. As the name suggests, its the context of current state of the application/object. It lets newly created objects understand what has been going on. Typically you call it to get information regarding another part of your program. Context is used for many operations but mostly to load and access resources. This is why all the widgets receive a Context parameter in their constructor. In a regular Android application, you usually have two kinds of Context, Activity and Application. It’s usually the first one that the developer passes to classes and methods that need a Context. A Context is a handle to the system; it provides services l

All about AsyncTask

AsyncTask can be useful in situations when there is a need for doing a long task like calling Web service and then show it in the UI as soon as it is finished. 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 AsyncTask runs on a background thread and the result is published on the UI. An asynchronous task is defined by 3 generic types, called   Params ,  Progress   and   Result , and 4 steps, called  onPreExecute ,  doInBackground ,  onProgressUpdate   and   onPostExecute . When using AsyncTask make an internal class which extend AsyncTask class. You should override atleast one method of AsyncTask ( doInBackground ). private class DownloadTask extends AsyncTask <String, Void, String> {    // Run on UI thread    @Override     protected void onPreExecute() {       // do initialization      }    /