Category Archives: ANDROID

What are weak references? How it can be used to avoid memory leaks?

By | June 1, 2017

Weak reference objects, which do not prevent their referents from being made finalizable, finalized, and then reclaimed. Weak references are most often used to implement canonicalizing mappings. Suppose that the garbage collector determines at a certain point in time that an object is weakly reachable. At that time it will atomically clear all weak references… Read More »

Android Speech to Text Tutorial

By | June 1, 2017

Android comes with a built in feature for Speech to Text. This is really helpful when you want to provide navigation in your app through voice commands. When you say something in the app, your voice will be streamed to the server and the server will convert it to text and send back. You can… Read More »

What are the different Logging options available in Android?

By | May 29, 2017

Android uses a centralized logging system. However you can write your own custom log statements. Log Statements To write log statements, you use use the android.util.Log class with the following methods: Log.v() Log.d() Log.i() Log.w() Log.e() Log.wtf() They are sorted by relevance with Log.i() being the least important one. The first parameter of these methods… Read More »

How to automatically generate comments for your function in Android Studio?

By | May 27, 2017

This is a simple trick in Android Studio. First you have to write the skeleton of your function like this Now to generate the comments for this function just type “/**” on top of the function and hit “enter”. You will see the comments generated for you. Now your function will look like this Leave… Read More »

Simple Image Scaling Demo in Android

By | May 20, 2017

This article shows how you can do simple image scaling in Android. Here I have a simple class that Scales the image. The Utility class Layout The layout which shows the image for scaling. Set the above xml as layout for the Activity. Activity Please leave your comments at the end of the post.

Using Popup Window in Android

By | May 10, 2017

The popup windows is a floating container that appears on top of the current activity. Layout for PopUp Below is the layout for the popup window. Layout for Activity Create another layout for the activity activity_main.xml Implementation The activity which implements the popup.

Client-Server Programming in Android. Send Message to the Client and Back.

By | May 1, 2017

Hi all, Today I will show you how you can implement Client-Server architecture in an Android environment.   Watch Video Demo   Below is the demo of the app we are going to build.   Watch Video Tutorial   I wil be explaining the code in the below video tutorial. If you have any comments,… Read More »

Using Shelvesets in TFS

By | April 30, 2017

Using Shelvesets in TFS we can set aside pending changes in Visual Studio 2015. We can set aside a batch of pending changes from our current work space temporarily using the feature Shelvesets . We can later restore these changes into our work space or can into work space of another user. Read more from… Read More »

Android Testing Tools

By | March 30, 2017

Automated testing processes are now a common thing in every project. Lets see some of them MonkeyRunner You can checkout more from here Advantages Low Level tool Does not have to do coding to automate tests Written in Python It can run test cases on rela devices connected to a PC/Emulators. APIs available for controlling… Read More »

Find subscriber id, sim serial number, phone network type etc in Android

By | March 20, 2017

The android.telephony.TelephonyManager class provides information about the telephony services such as subscriber id, sim serial number, phone network type etc.You can also determine the phone state etc. Permission Before Starting, make sure you add the permission in the Android Manifest. Android Source Code Below code gets the information from the Android Telephony Manager and displays… Read More »

Using SmsManager to send SMS

By | March 1, 2017

There are two ways to send SMS in Android Using SmsManager Using Built in Intent 1. SmsManager The SmsManager manages SMS operations such as sending data to the given mobile device. You can create this object by calling the static method SmsManager.getDefault() as follows: Initialize Sending Message Once you have SmsManager object, you can use… Read More »

Check if the Device is Charging in Android and the Power Source.

By | February 20, 2017

Your application peformance should be upto the mark. But it should perform differently not on the front end , but on the back end when it the device is connected to a power source or charging. Charging could be of from USB and from wire cable. When your device is charging itself , it is… Read More »

Using Different Media Libraries in Android

By | February 5, 2017

Android provides two main API’s for playing sounds. SoundPool MediaPlayer SoundPool SoundPool can be used for small audio clips. It can repeat sounds and play several sounds simultaneously. The sound files played with SoundPool should not exceed 1 MB. SoundPool does load the file asynchronously. As of Android API8 it is possible to check if… Read More »

Event Handling using DataBinding in Android.

By | February 3, 2017

Using data binding, you can also handle events right from the layout xml using either Method references, or Listener bindings. For this we can create a seperate Class named “MyHandler”. Event Handler Class MyHandler.java Like my previous examples you have to initialize the listener in the Activity. Layout Now the layout that has a button… Read More »

DataBinding in Android using Observable Collections

By | January 30, 2017

As I shown in the previous post where we used BaseObservable and ObservableField to update UI when binding object is changed, this post will show you another simple way to achieve this. Do Check my previous posts for better understanding of DataBinding and methods used in DataBinding. http://www.coderzheaven.com/2017/01/15/simple-databinding-in-android-example/ http://www.coderzheaven.com/2017/01/20/data-binding-in-android-using-observables/ http://www.coderzheaven.com/2017/01/25/data-binding-in-android-using-observablefield-to-update-ui-automatically/ Here is another way to… Read More »

Data Binding in Android – Using ObservableField to Update UI automatically

By | January 25, 2017

As I shown in the previous post where we used BaseObservable to update UI when binding object is changed, this post will show you another simple way to achieve this. Do Check my previous posts for better understanding of DataBinding and methods used in DataBinding. http://www.coderzheaven.com/2017/01/15/simple-databinding-in-android-example/ http://www.coderzheaven.com/2017/01/20/data-binding-in-android-using-observables/ Here is another way to do it. In… Read More »

Data Binding in Android – Using Observables (BaseObservable) to Update UI automatically

By | January 20, 2017

In the last example, you may have got an idea of what DataBinding is. If not please check my tutorial here… Simple DataBinding in Android Example. Updating Objects using Observables. In the last tutorial you may have noticed, if you update the object which is data binded, the change is not reflected in the UI… Read More »

Using GSON in Android – Simple Demo

By | January 19, 2017

GSON is open source Java library developed by Google. It is an API for converting a Java object to json representation and viceversa. Uses Converts any Java object i.e new object or any existing/legacy object, to JSON and vice-versa. Finest support for generic objects Simple, convenient methods for conversions No need of any annotation for… Read More »

Android Navigation Drawer Simple Example

By | January 16, 2017

Navigation Drawer helps developers for creating easy menus in an application. Lets start to see how it works. We will start by creating a new project with a navigation drawer activity. Adding Navigation Drawer Activity If you want to add Navigation Drawer Activity to your existing project you can simply add it by going to… Read More »

Simple DataBinding in Android Example.

By | January 15, 2017

This is a latest technique in Android where the UI is updated when the data bind to it changes, which is called databinding. DataBinding DataBinding has its own expression language for layout files. It corresponds to Java expressions and has quite impressive capabilities. Below you can see the list of all available operators: mathematical operators;… Read More »

How to call Android function from JavaScript?

By | January 10, 2017

Check the Video below to see what we are going to do… If the web page you plan to load in your WebView use JavaScript, you must enable JavaScript for your WebView. Once JavaScript is enabled, you can also create interfaces between your application code and your JavaScript code. Enabling JavaScript JavaScript is disabled in… Read More »