Author: Lalit Vasan

Android Developer
April 20, 2017

Android How to convert Dp to Px and Px to Dp

If you are developing an android application that is based on inflating views at runtime and are dependent on height and width of the screen. You often need to Convert Dp to Px android and convert between real pixel (px) and device independent pixel (dp, dip). Most of the use case of converting dp to pixels come when you are inflating a view from code. […]

April 20, 2017

What is the difference between “px”, “dp”, “dip” and “sp” on Android

When you are creating the UI layouts of your application, you usually define dimensions with units like px, dp, dip and sp. Pixels(px) – corresponds to actual pixels on the screen. This is used if you want to give in terms of absolute pixels for width or height. Density-independent Pixels (dp or dip) – an abstract unit that is based on the physical density of […]

March 9, 2017

How To Reduce Android APK Size

Android Application Size really matters when going live to the play store. Users often avoid downloading apps that seem too large, particularly in emerging markets where devices connect to often-spotty 2G and 3G networks or work on pay-by-the-byte plans. I would like to share the few approaches which you can use to reduce apk size without impacting the quality of your app. 1. ProGuard ProGuard […]

January 16, 2017

What is Context in Android

What is Context in Android? Android is an 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. Different ways of getting context → getContext() → getBaseContext() → getApplicationContext() → this […]

January 15, 2017

How to Get Current Screen Orientation in Android

Android devices have both landscape and portrait modes and can flawlessly move between these modes. The Android working framework naturally handles these progressions for your application. You can also detect in which orientation is your android device. The natural orientation of a device is the orientation in which the orientation is 0 on all the three axes. Below method returns the current screen orientation mode […]

January 14, 2017

Android How to Get Phone Unique Device Id

Sometimes it is required to get the unique ID of android device while developing the android application. This is necessary in cases when the you wants to track the unique device installations of the application. There are many ways to get android device unique ID so below method is a relevant way to get ANDROID_ID via Secure class. Below method returns a 64-bit number (as […]

January 4, 2017

Android How to Check Internet Connection Status

If you are developing an android application that perform internet related operations like calling web API, loading web page in Web View, uploading profile pic and etc. So before performing any internet related tasks it is better to first check that your device is connected to internet or not . Android provides ConnectivityManager class to know about the internet connection status. The following method will […]

January 3, 2017

How to Hide and Show Soft Keyboard in Android

There may be a case where you want to hide or show the soft keyboard. The case may be for example, you are done with entering text in search view and based on your selection from the suggestion list you want to take some action and also want to close (hide) the soft keyboard. You can hide or show the soft keyboard programmatically in Android […]

December 26, 2016

How to Get Width and Height of Android Screen in Pixels

Sometimes you want to know the screen width and height in pixels. An example can be that you are developing a system information app and you have to display screen width and height in your activity. This is going to be so simple with very few lines of code. The following code snippet give you the screen width and height in pixels. Display display = […]

December 25, 2016

Android How to Check Service is Running or Not

In some cases you might want to check that a service is running or not. An example user case would be, in your app there is a service that sync data to server and you have given user the possibility to toggle the related service on and off. So how do you know that the service is currently running or not? To Know service running […]