Showing posts from March, 2018

BatteryStats and Battery Historian in Android

While developing android apps, it is our duty as developers to make sure that our apps are good citizens in terms of Battery consumption. Android framework has two main tools, BatteryStats and Battery Historian.  

First will explain BatteryStats and Battery Historian.

BatteryStats Batterystats is a tool to dump the battery data of the device to the development machine.

BatteryHistorian Battery Historian converts the report from batterystats to a HTML visualization that we can see in the browser.

Through these tools we can identify
where and how processes are drawing the battery & identifying tasks which can be deferred or even removed to improve the battery life.
Steps to install BatteryHistorian are,

1. Install docker software from here

2. Git clone the repo from here

3. Then run the command in terminal
docker run -d -p 9999:9999 bhaavan/battery-historian
4. Type in address bar of the browser,
5. Then run the command in terminal
adb bugreport > bugre…

Retrofit2 - Simple basic example

Here, I am going to explain the use of retrofit library in android. The tutorial has two api calls, one to get the model class and another to get the JSON as string. Another point is, according to the response we need, we have to pass the appropriate "ConverterFactory" to retrofit object.

The step by step tutorial

1. First add the dependencies in gradle,

compile 'com.squareup.retrofit2:retrofit:2.1.0' compile '' compile 'com.squareup.retrofit2:converter-gson:2.1.0' // for scalar converter factory compile 'com.squareup.retrofit2:converter-scalars:2.1.0'

2. Then create a ApiInterface class and add the api calls we need. The return type of the methods are "Call". One point to note in Call is execute() call is a synchronize call and enqueue() is an asynchronous call. In addition to that, BASE_URL should end with "/", else we will get an IllegalArgumentException

public interface APIInterf…