Posts

Show the updated battery status in Android

Have a happy holidays. After a long time, I'm blog here such a good topic. Here I explain about the battery status on real time. Yes, you can use BatteryManager to get the battery status. But you want to know the updated status on all time means, you need to use BroadcastReceiver. You can add on your activity.  private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() {         @Override         public void onReceive(Context context, Intent intent) {             int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);             int icon_small = intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, 0);             int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);             int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);           ...

HTTP vs XMPP

http - hyper text transfer protocol xmpp - eXtensible messaging and presence protocol. Both http and xmpp is communication protocol and open source. But their uses is completely different. XMPP is mostly used in chat type application. XMPP is faster than HTTP. It's a bi-directional functionality. Like chat application, user sends message from device, it's re-directs to server and receive's message to another user. It's handle both upstream and downstream.

Proguard usage in Android

Hi friends, have a great day. Now I'm going to explain the what is proguard and it's usage in android. Believe android is big sea, there is lot of things. What is Proguard? Proguard is a simple java tools to shrink apk, prevent re-engineering from hackers. It's a reduce the size of android apps and run faster. Proguard renames the classes, methods and objects to prevent the re-engineering the APK. Now hackers easily to hack your code and run for their uses. Proguard stops them and protect your code. In android project, proguard located in apps folder. proguard-rules.pro To enable the code shrinking, just add simple line in gradle. It's under buildTypes{    release{       minifyEnabled true       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'    } } Please follow the below lines, that's very important to make it. -dontusemixedcaseclassnames #Specifies not to generate mixed-case c...

Speed up gradle build in Android Studio.

Image
Hi friends, have a great day. In android development, initially most of developers are learn on eclipse, then android studio came with a lot of features. Most of developers hate because of GRADLE. In eclipse, we using maven. But gradle is completely different. Take a long time for making a build. Please don't take seriously, if you have enough RAM, Internet and good speed of processor. :) I give some suggestion to perform the faster gradle build. 1. Append the following lines in gradle.properties in your app. # The Gradle daemon aims to improve the startup and execution time of Gradle. # When set to true the Gradle daemon is to run the build. # org.gradle.daemon=true # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. # org.gradle.parallel=true # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10...

Singleton classes

Most of interviewers asking the question to java and android developers. It's not strange. We need to explore this. Singleton:   Create the only one instance in the class.   Provide a global point of access to the object  Allow multiple instances in the future without affecting a singleton class's client In android applications, It's help to hold the global session data. It's easily to call from another class. Imagine, If you creating the MyApplication class, that's need to be access in all over the application means. private static MyApplication sInstance; public static MyApplication getInstance(){       return sInstance; } public void onStart(){ --- } public void onTerminate(){ -- } public void onPlay(){ -- } If you want to access onStart(), onTerminate() or OnPlay() methods from another classes means, you need to use singleton. So buddies, I hope you clear now. If you not clear, please practice....