Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Friday, October 20, 2017

(Note: This app was published with the name Save Me -Pocket Lite which is changed to Linkaive later on.)

TL;DR

Linkaive is an Android App designed for Readers, Quorans and all Internet Users who like to save and backup Links/URLs on the go.

The Problem

While surfing the internet we came across so many links, and references that we feel like it will be useful in future. So what we used to do, we bookmark all those links in our browser, but now, all those links are limited to that particular browser. Some of us must have used the ‘Pocket’ App for this purpose. And being an existing user of the Pocket App, you must already know, it consumes a lot of internal memory, mine reached to almost 1.5 GB.
Even if you have found a way to save your favorite links, you can not recall them as you can not search for its content. And that’s another story that we do not have control on those saved links.
If you are a Quaran, how many times have you searched for a way to save your favorite answers? Yeah, I know the pain.

The Idea

There must be a way, independent of any browser which can bookmark and save unlimited links without any condition. Then, why not an Android App? Nowadays, being online is not a big deal, but the internal memory is. So the App should consume least internal storage irrespective of the links saved in it. The App should allow me to search for links and it’s content. The App should offer me a full control over all my links saved.
The most importantly it should work even offline, without internet. And it should be able to save links to your favorite answers on Quora.

The Solution

Linkaive an Android App to the rescue.
It is an Android App designed for everyone which overcomes all problems mentioned above and willing to offer many best features for free. It is created for Readers, Quorans and all Internet Users who like to save and backup Links/URLs on-the-go.
To summaries, it is the lighter version of the Pocket App. But the advantage of Linkaive App is, it consumes very less internal storage. And it also allows you to browse the saved links inside the App.

Some Features of the App

  • Hassle free way to add new Links/URLs- You can add new Links/URLs manually using floating add button in App. You can all also add new Links/URLs using any other App using share feature of that particular App.
  • Marks Links/URLs as Favorite.
  • Search for Links/URLs and it’s content even if you are offline.
Now it’s time to use the Linkaive Android App. Add comments to request new features. And do not forget to rate the App 5 star on Play Store.

Thanks for reading the article.

Play Store link to the App- Linkaive on Play Store.

Thursday, October 5, 2017



My name is Rohit and from past 1 year, I have been working as an Android Developer. Now you may think why should you read an article written by a guy who has only 1 year of experience? But wait what makes me different from others is my one of many habits. I think, my habit of learning at least one new thing every day makes me different. So I have learned 300+ new things last year. And I have already used many of it in practical. It’s enough about me, let's move on to the main topic.
I have been working on an app from few months. Basically, it showcases information stored on the server. And the app was completely online. Down the line, I felt like adding an offline feature to this app so as to make its usability better. So lately I decided to add an offline functionality support to my app. So taking this thought process of adding offline support to my app ahead, the first question that came to my mind was -

What are the available options?

In Android, we can sync server database to local storage mainly using

  1. Sync Adapters
  2. Custom Services
  3. Other services like Firebase

Sync Adapter and Content Provider

If we want to share app’s private database with other apps, we have to use Content Provider. Content Provider is the one who decides which app can access a private database. The best example of this approach is our contacts which are accessible to all other apps that have permission. On top of Content Provider, there is a Content Resolver which has all functions useful to interact with the private database. Later comes the Sync Adapter. Sync Adapter synchronizes server and local database using Content Resolver. Content Resolver acts as an interface between Sync Adapter and private database. Sync Adapter is specially designed service which is useful to transfer data between server and device using predefined schedules and triggers. Sync adapter adds an option in “Settings — Account — Your App” to set your sync preferences. It's optimized and recommended way to sync server database continuously. So if you decide to use Sync Adapter in your app, your app’s structure will be like-
Online Database => Sync Adapter => Content Resolver => Content Provider => Private Database
 => Custom Services

Here I will write about normal Services and Intent Services only. Intent Services are simply awesome. It's already bound to your app. It creates its own worker thread so you don’t need to create your own thread to run in the background. It gets destroy on its own, you don’t need to call stopSelf() on intent service. But wait if you are already using Volley library in your app, then you should not make use of Intent Service. Because Volley processes API call in a separate thread and returns result to the calling thread. If you are using Volley and Intent Service simultaneously, you will end up main thread creating separate worker thread (by Intent Service) and that worker thread creating a separate thread (by Volley) for API request. So there are many scenarios where you will leak memory through your app.
So if you want to use Volley for synchronization efficiently you should use normal Service. Using Volley in Service you don’t need to create separate background thread so that you can be sure that app will not leak memory easily. So I have decided to use normal Service in my app.

Local Storage - SQLite

Although there are some alternatives to SQLite in Android, I have decided to go with the default option which is SQLite. Maybe next time I will think of other alternatives. So my plan was-
  1. Create Helper class which will create or upgrade database and tables.
  2. Create a Handler class which will have functions to interact with the database.

Here are some code snippets, you can refer -
My DatabaseHelper class



My DatabaseQueryHandler Class


Abstract Methods

SQLite Database Abstract Methods- Insert, Query, Update, Delete. Even though there are specific functions in Android, here I am going write about the best suitable approach for each method.


Insert -

For insert query, I have used Prepared Statements. It's the best way to insert/update/delete multiple rows at a time. Prepared statements improve the speed of transactions using the concept of Transactions and Compile-Statement. It's faster because the query will be compiled only once throughout the transaction.
Example -
 //SQL Prepared Statement
 String insertPreparedStatement = “INSERT INTO “ + DatabaseHelper.TABLE_CUSTOMER_DETAILS + “ VALUES (?,?,?,?,?)”;

Query/Search-
We cannot use Prepared Statements for queries which returns some data.
So you have to use "query()" function of SQLite database. This function returns Cursor object, which can be used to access values of each row.
Syntax of query() function
//Cursor cursor = sqLiteDatabase.query(String tableName, String[] tableColumns, String whereClause, String[] whereArgs, String groupBy, String having, String orderBy);

Update -
There are two optimized ways to update all /selected rows of a table in the database. And of course, both ways works with prepared statements.
1. Using “INSERT OR REPLACE INTO” keyword — used to insert/replace a row in a table using primary key only. It doesn’t allow you to use WHERE clause. If a primary key exists then replace row (delete and then insert row) else insert row directly. You can use this keyword instead of INSERT to insert rows in the table.
2. Using “UPDATE” keyword — used to replace selected values/columns from the table using WHERE clause. It is helpful when you have to update table data/row independent of a primary key using WHERE clause.
Example- UPDATE TABLE_NAME SET COLUMN_1=?, COLUMN_2=? WHERE COLUMN_3=?


Track Memory Leaks

Now you must have got an idea of, which type of query can be used where. After implementing this, next came to my mind was-
How can I track whether my app is leaking memory or not? & How can I be sure that my app will not leak memory?
So I had a look at some options to resolve this issue and I found a library called Leak Canary.
Even though the issue looks difficult, you can make it simple by using this library. This library alerts you whenever app leaks memory so you can keep track of memory leaks in your app.
After digging out every possible information about services, local storage, threads, volley, transactions, SQLite, its different queries and much more, I feel proud that I have achieved my target in predefined deadline. 
I hope my story will help others who are looking for a better solution to synchronize their app with the server database.

(Sources- Title Image: www.iconfinder.com) 

Originally Published on Medium January 29, 2017.


Do you ever caught in a situation, when you don’t want to create separate app icons for multiple screen sizes?
Do you think that you are tired of traditional way of re-sizing app icons?
If yes, then there is an automated way to create and resize app icons for multiple screen sizes - Vector Asset Studio to use Vector Drawables.

Summary


  • What is a Vector Drawable? 
  • How to create Vector Drawable?
  • Vector Drawable Image vs Raster Image
  • How to use Vector Drawable?
  • What is Vector Asset Studio?
  • How to use Vector Asset Studio?
  • Useful Attributes and Example.
  • Backward Compatibility.



Advantages

What is a Vector Drawable?

class - VectorDrawable extends Drawable                   
In android 5.0 (API Level 21) Google introduced a support for Vector Drawables. Vector Drawable image is simply XML file which contains all the geometrical information of an image such as a set of points, lines, and curves, as well as their associated color information.

How to create Vector Drawable?

Crating Vector Drawable is two step process.
  • Note: You can also use Googles Inbuilt Material Design Icons.
  1. Create App Logo in any professional image editor and then save or export that image as SVG format. (Scalable Vector Graphics (SVG) is an XML-based vector image format.)
  2. Use Android Asset Studio to convert that SVG image into XML format. The detailed process can be found below.

What is Vector Asset Studio?

In latest android studio google introduced new tool Vector Asset Studio. With this tool, importing SVG files is became easier and we can now use any of the material design icon vector assets provided by the software. The Vector Asset Studio generates a XML file for VectorDrawable using data from a SVG file.
Vector Asset Studio helps us to add material icons and import Scalable Vector Graphic (SVG) files into our app project as a drawable resource. Compared to raster images, vector drawables can reduce the size of our app and be resized without loss of image quality.

How to use Vector Asset Studio?

Running Vector Asset Studio in Android Studio:
Follow these steps to start Vector Asset Studio:
  1. Open an Android app project.
  2. In Project window, select the Android view.
  3. Right-click the res folder and select New > Vector Asset
  4. Continue with Importing a Vector Graphic.
Referring to a Vector Drawable in Code:
Ex. In XML Code

Ex. In Java file
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.myimage);

Backward Compatibility:

Android 4.4 (API level 20) and lower doesn't support vector drawables. But dont worry if our minimum API level is set at one of these API levels, Vector Asset Studio also directs Gradle to generate raster images of the vector drawable for backward-compatibility.
For Android 5.0 (API level 21) and higher, Vector Asset Studio supports all of the Vector Drawable elements. For backward compatibility with Android 4.4 (API level 20) and lower, Vector Asset Studio supports the following XML elements:

<vector>
android:width
android:height
android:viewportWidth
android:viewportHeight
android:alpha
<group>
android:rotation
android:pivotX
android:pivotY
android:scaleX
android:scaleY
android:translateX

Advantages:

  1. Vector drawables scales without losing image quality.
  2. We need only one asset file for multiple vector images.
  3. Vector drawables can reduce the size of our app.
  4. We can import Scalable Vector Graphic (SVG) files into our app project as a drawable resource.
  5. Help us to easily support different Android devices.
Example:
Vector image with the shape of a heart- heart.xml


(Sources- Title Image: www.designplusph.com)

Originally Published on LinkedIn in January 21, 2016.