Posts

Showing posts from September, 2014

Android Async Task With Example Use Case

Why Async Task Androids Application UI is single threaded and executed by one Thread called UI Thread. If we want to execute slightly long running processing by UI Thread then the Application would become unresponsive and the User experience will not be great. AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread. An asynchronous task is defined by 3 generic types, called Params , Progress and Result , AsyncTask have Four Main Method... onPreExecute()  doInBackground() onProgressUpdate() onPostExecute()  onPreExecute() This task is run on the main UI Thread, This method can show update the UI on the Activity hinting the start of the background process, like updating the UI with Progress Indicator. doInBackground(Params......) Invoked on the Background Thread.This method is executed right after onPreExecute() method is finished. Code for long running operations like up

REST API using Play! Framework in JSON and XML Format

Play Framework  Play is heavily inspired by Ruby on Rails . Play supports both Scala and Java and enables developers to develop application faster by following convention over configurations. The following post describes how we can expose REST API Endpoints very quickly supporting multiple format like JSON XML etc using Java with Play Framework. Rest End Point Example  Say We want the List of Users to be exposed as a JSON Response with an endpoint. We will achieve the same with the following steps. Step 1: Define the Routes and Controller Mapping Step 2: Define Entity(Model Object) Step 3: Define the Controller Step 4: Start the Play Application Step1: Define the  routes (/conf/routes) Open the /conf/routes file and add the following line(s). GET /api/v1/User/details/all controllers.MyApplicationApiV1.getUserList() GET /api/v1/User/details/{userId} controllers.MyApplicationApiV1.getUserDetails(userId: Long) These entries in the routes file says that map

Accessing Android SQLite Database

When developing Android Application that stores data in SQLite Database, it is very useful to directly access the Database on the Emulator or Real Device from the Terminal to Debug or Test. For instance as a Developer I want to verify data is saved in Database, debugging SQL Queries etc. Here are the steps to be followed to connect to the SQLDatabase of the Device From the Command prompt First Start the Android Emulator or connect a Android Device with the System.  Once The Device is connected we can access the Shell of the device though ADB. Note that ADB should be installed on the System from where we want to access the Android Database(s). After the Device is connected open a Terminal and follow the following steps. 1) Get The List of Active Devices $adb devices List of devices attached emulator-5554 device This will give list of emulator or Devices connected to the System. (For me it is showing only one active Emulator emulator-5554) Say we want to connect to dat