Posts

How to use LocalBroadcastManager?

                LocalBroadcastManager allows to register and send broadcasts to local objects within your application. Advantages over sending Global Broadcasts: ·          No need to worry about leaking of data as the data you are broadcasting never leave your app. ·          It is more efficient than global broadcast. ·          Not possible for other applications to send these broadcasts to your applications. LocalBroadcastManger is introduced in android 3.0, so you have to use android support library v4 for prior releases. Create receiver.  private BroadcastReceiver mReceiver = new BroadcastReceiver() {             @Override             public void onReceive(Context context, Intent intent) {                   // your code             }       } Register receiver LocalBroadcastManager. getInstance (getActivity()).registerReceiver( mReceiver , new IntentFilter("loc_receiver")); Send Broadcast Intent intent = new Int

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      }    /

Adding events to Android Device Calendar

Here is the code to add an event to the Calendar

Android

Android is an operating system for mobile devices such as smartphones and tablet computers. It is developed by the Open Handset Alliance led by Google. Google purchased the initial developer of the software, Android Inc., in 2005. The unveiling of the Android distribution on 5 November 2007 was announced with the founding of the Open Handset Alliance, a consortium of 80 hardware, software, and telecommunication companies devoted to advancing open standards for mobile devices. Google released most of the Android code under the Apache License, a free software license. The Android Open Source Project (AOSP) is tasked with the maintenance and further development of Android. Android consists of a kernel based on the Linux kernel, with middleware, libraries and APIs written in C and application software running on an application framework which includes Java-compatible libraries based on Apache Harmony. Android uses the Dalvik virtual machine with just-in-time compilation to run compile