Posts

Showing posts from January, 2017

Avoid Memory Leaks and understanding of reference in Android

Memory management is a serious problem for Android development. Memory leaks play a very important role to achieve into it. Memory leak is when an object is no longer being used but unable to be Garbage collected because it is still being referenced some other places in the application. As a result, this unused object is occupying the memory resource even though it is not being used by the application. Too much unused objects inside application will cause not enough memory left for other active objects and finally leads application crash with OutOfMemoryError. That means to take care of memory; you might need some different strategies such as: Search for memory leaks (Even when things aren't failing). Keep track of your references. Different Ways to Memory Leak in Android Below are few different ways which can lead the memory leak problem. So when you come across following situations, make sure you handle it properly- Static Activities or Views Inner C

Secure and smaller APK size using Proguard

Proguard is a tool which shrinks, optimizes, and obfuscates code. It detects and removes unused classes, fields, methods and attributes from APK. It optimizes bytecode and removes unused instructions. It renames classes, fields, and methods via meaningless names. Why Proguard for Android? Shrinking contribute towards a work around for 64k reference limit of Android Application. Optimization analyzes and optimizes the bytecode of the methods. The obfuscated code makes APK difficult to reverse engineer, which is especially valuable for app security. The result of above all is smaller APK size and more difficult to reverse engineer. Enable Proguard in Android Studio To enable code shrinking with ProGuard, add minifyEnabled true to the appropriate build type in your build.gradle file. android {     buildTypes {         release {           minifyEnabled true           proguardFiles getDefaultProguardFile('proguard-android.txt'),proguard-

Faster Android development with data binding

Android Data Binding creates a link between UI layer and the underlying data model that holds the information to display. In normal Android app, it is necessary to find the view and update the content. Every time data changes the User Interface widget (TextView, ImageView etc.) bound to it is needs to be update. Lots of hours were wasted on writing and maintaining trivial and almost useless code occupying tens or even hundreds of lines in almost all Activity. Android Data Binding library minimize the code for app logic with its UI view. It eliminates the need for these method calls “findViewById” and “setText.” The real power of data binding is when the updating of a value occurs at many points in an application code. In that situation, the developer doesn’t have to keep track of all the ways a value can be updated. Using data binding can lead to faster development times, faster execution times and more readable and maintained code. Android data binding generates binding cl