Using ORMLite in Android Mobile Apps


ORMLite (Object Relational Mapping) database provides lightweight data mapping between Java Classes & SQL Databases. ORMLite mainly supports the following JDBC connections: MySQL, Postgres, H2, SQLite, Derby, HSQLDB, Microsoft SQL Server and so forth.

Since it is not an in-built library in Android like SQLite, developers need to add the respective Jar file or dependency first before starting development.

Why ORMLite?

Before delving into the topic of ORMLite, we need to understand why we need ORMLite. As compared to SQLite database in an Android library, ORMLite can be used repeatedly without making too many changes to the code (in terms of queries).While dealing with ORMLite, it is not necessary to learn SQL as another language since we can use objects and pre-defined methods to create our database.

How to start & use ORMLite:

To start development using ORMLite in Android, we need to follow the below mentioned steps:

Downloading ORMLite jar file (Android):

For using ORMLite with Android application, you should download ormlite-android-4.43.jar and ormlite-core-4.43.jar & above version files. Add them as library files to the project and you are ready to start the development.

Configuration of your model class:

After successful download of ORMLite jar files, the second step for a user is to configure their Model class. Users can use the following annotations to configure their classes.

  • @DatabaseTable: The @DatabaseTable annotation is used to provide a specific user-define name to a database while creating a Database Table..
  • @DatabaseField: The @DatabaseField annotations are used to provide fields to the database created.
  • @DatabaseField(id=true): The @DatabaseField annotation is used if a user need to declare any of the fields created in the database as a Primary Key.

Below is an example to demonstrate ORMLite model class:


@DatabaseTable(tableName = "employee")
 public class Employee{
 @DatabaseField(id = true)
 private String name;
 private String empID;
 Private double salary;
 public Employee() {
 // ORMLite needs a no-arg
 constructor with package visibility.
 public Employee(String name, String empID,String salary) { = name;
 this.empID = empID;
 this.salary =salary;
 public String getName() {
 return name;
 public void setName(String name) { = name;
 public String getempID() {
 return empID;
 public void setempID(String empID) {
 this.empID= empID;
 Public double getsalary(){
 return salary;
 public void setsalary(double salary) {
 this.salary= salary;

Configuration of DAO:

DAO stands for Data Access Object which provides us CRUD (Create, Read, Update & Delete) database operations. The simplest way to create a DAO is to use a static createDao method in the DaoManager class. The DAO of Employee class defined will look like:

**Private Dao<Employee,String> empdao = DaoManager.create(connectionSource,Employee.class);

Custom Statement Builder:

DAO has some pre-defined methods to query for an object that matches an ID field as (queryForId) & if it matches all objects, then (queryForAll) and some other simple matching methods. However, for more custom queries we have queryBuilder() method which returns a QueryBuilder object for a DAO with which you can construct custom queries of your database tables.

Query Builder Basics:

To start working with query builder, we have to first provide column names to our database fields so that it will be easy for us to use them while building our query. Below is an example to show how to build a query in ORMLite:

@DatabaseTable(tableName =“Employee")
 public class Employee{
 public static final String FIELD_NAME = "name"; ...
 @DatabaseField(canBeNull = false, columnName = FIELD_NAME)
 //this will check that the name given by user to column FIELD_NAME should not be empty
 private String name; …
 Now let us start building query as:
 QueryBuilder<Employee, String> queryBuilder = empdao .queryBuilder();
 Where<Employee, String> where = queryBuilder.where();
 where.eq(Employee.FIELD_NAME, "Rohit");
 where.eq(Employee.FIELD_Emp_ID, "12345");
 PreparedQuery<Employee> preparedQuery = queryBuilder.prepare();

Using this With Android OS:

While working with Android operating system we need to create our own database helper class extends to OrmLiteSqliteOpenHelper class. This class creates an override method as onCreate and onUpgrade .These override methods create and upgrade your database when your application is going to start and can also provide the DAO.

Classes used by other classes:

While working with this, you should keep your helper class as public so that all other classes can easily access it. Once you have defined your database helper you need to use it in your activities.

The simple method to use your OpenHelperManager is to extend it to OrmLiteBaseActivity for each of your activities. If you don’t want to follow the above method you can directly call OpenHelperManager.gethelper() method to your respective classes.

Once you use OpenHelperManager.gethelper() save the helper class and then call OpenHelperManager.release() to release the call.

Table Config File:

We have used ORMLite annotations for configuring our class. If required you can also remove the annotations which makeour data access objects operations a bit faster.. In ORMLite you can configure data using a text configuration file. This configuration file consists of different tags related to database table and the fields associated with it. The OrmLiteConfigUtil class writes this config text file in android raw resource folder and can be declared in your database helper class. Below is an example of config text file:

public class DatabaseConfigUtil extends OrmLiteConfigUtil {
 public static void main(String[] args) throws Exception {
 } }

How to update Android Apps Outside of Google Play

Here’s a DIY on how to programmatically make your Android phone look like an iPhone.

Having an Android device is beneficial as we can install apps as per our need. Many of us might already be familiar with Google play store which is the app store for Android and have been using it for downloading apps. It is Play Store which is responsible for notifying us of any updates to the installed app. These updates might carry bug fixes, enhancements to existing features or may also include addition of new features.

However, it is up to the users to decide whether to permit Play Store to update these installed apps to the latest version or not. Despite all these facts, Google has not restricted users to get apps from outside its play store. And this is where Google separates itself from other mobile platforms.

The main issue with Google play store updates is the fact that the store takes its own time for updates. To explain further, once the latest application has been uploaded to the store, it lines up all the existing users in a queue and then starts pushing the updates to the users, one by one. Thus, if the number of users are more, it takes more time. If at all, the new application has to reach all the users immediately, then we may have to handle the update programmatically by leaving Google Play store’s auto -update functionality.

Apart from Google play store, there are many other app stores where you can upload the application binaries (apk files).  Even in these stores, users can download the app by sharing app link and also provide updates whenever a latest version of app is available on the store. Some app stores provide free publishing as well.

 Given below are a few such app stores for Android:

  1. Amazon App Store
  2. Mobile Market
  3. Opera Mobile Store

However, this is not the only way you can install an app. You can install apps even without publishing it in any of the above mentioned third-party stores.

 How to programmatically install/update apps?

 Given below are instructions to achieve successful installation/updation of a mobile app without using Google Play store or any other store.

  • For devices, if it is the first time that you are installing any app outside Google Play Store, you can go to Settings and select Applications to check the “Unknown Sources”.
  • Build your app always with a valid version code and version name, and always ensure that manifest file of the app is updated to the next incremental number in version code.
  • <manifest xmlns_android=""
     android_versionName="1.0" >

    Once the build is ready it can then be either placed in phone storage for installing it and upgrading to the latest build directly by using any file manager. Or can be placed in any webserver or a cloud space provider like dropbox and can use that link for downloading and then installing on the device.

  • The best approach to follow will be in instances where the user gets a notification for new updates using custom GCM push notification. The user can then decide on whether he wants to update the app immediately or later. But once clicked on notification, the code can be put to download the file and then go for installation.
  • Following code can be used to install/update the application after successful download of apk:
    Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + appFilelocation.toString()), "application/"); startActivity(intent);

    AndroidManifest.xml requires following permission:

  • <uses-permission android_name="android.permission.INTERNET" />
     <uses-permission android_name="android.permission.INSTALL_PACKAGES" />
     <uses-permission android_name="android.permission.WRITE_EXTERNAL_STORAGE" />

    User vs System Mobile Apps

    These apps can be just User Apps or System Apps. User Apps are ordinary apps which do not interact with internally restricted features on the device. System apps can be a combination of user apps along with codes written to interact with system restricted features. If your app is System App, then it can change the entire way of downloading and installing the new updates for the device to a whole new level. Instead of asking user permission for updating, it can be coded to an extent that the power of installing the updates is decided by the app itself and can be automatically updated without the user’s notice!

Enjoy Building!! In case you need expert help, reach out to us. Trigent’s mobility experts have decades of experience working on different platforms, tools, and technologies to guide and support your application development.

The What, When & Why of Mobile Interrupt Testing

Read an overview of mobile app testing.

Mobile Interrupt Testing is a form of mobile application testing that deals with the behavior of an application when it is interrupted in the foreground and resumes to a state before the interruption.

Interrupt Testing, on the other hand, applies to any application type, i.e. web, mobile, stand-alone, etc. However, the variety of devices, networks, configurations, etc. makes this form of testing appropriate for mobile applications.

What is Mobile Interrupt Testing?

We all have our daily interruptions in day-to-day life. Consider a real-life example of being interrupted by a call when reading a newspaper. Some of us may notice the call, ignore it and continue to read the paper, some see the call, acknowledge it, and continue reading, a few more might attend the call, and then resume reading the paper. However, in all the above instances, one’s thought process when reading the paper has been interrupted or lost. To translate this to mobile technology, Interrupt Testing tries to find out which behavior your application exhibits when an interruption occurs.

Given below are a few examples of interruptions in smartphones:

  • Battery low
  • Battery full – when charging
  • Incoming phone call
  • Incoming SMS
  • Incoming alert/push notification from another mobile application
  • Plugged in for charging
  • Plugged out from charging
  • Device shut off
  • Application update reminders
  • Alarm or calendar reminders
  • Network connection loss
  • Network connection restoration

This list is not exhaustive and only includes the most common scenarios.

Before we move on let us understand the phrases, ‘application running in the foreground’ and ‘application running in the background’.

The application running in the foreground is the app on which the user has direct control and which will be seen on the smartphone screen.

Background applications are those apps running on the smartphone but on which the user will not have direct control until it is brought to the foreground. Apps running in the background are expected to resume to the last controlled screen/action when called to the foreground.

Usually, an app goes to the background when we open multiple apps and then we toggle between apps based on our need without closing/quitting the app. The app which is in the background will be using the memory of the phone till it is quit by killing.

The application needs to handle the interruptions adequately to meet user requirements. The expected behavior of an app for these interruptions might resemble the following:

  1. Run in the background: The interruption takes over while the application goes to the background. It gains control after the interruption ends. For example, A phone/WhatsApp/Skype call that you attend while you are reading/playing a game on the smartphone. When the call ends the game or the activity you were involved with, should resume to the state it was in, before the interruption.
  2. Show alert. Alert disappears, and you work as usual. ‘SMS received’- messages appear in the header. The user does not bother about it and continues working with the application as normal. Other mobile app alerts, such as a new friend request on Facebook or WhatsApp messages, also fall into this category. But if the user decides to read the message, the behavior described in Point 1 is followed. If ignored, the application’s state is unchanged.
  3. Call to Action: Alarms have to be turned off or snoozed before you continue working. The same thing applies to app update messages. You either have to ‘Cancel’ or ‘Accept’ the changes before you proceed. Another example is that of the low battery alert – You can choose to continue as usual or go into a low power mode (if the device allows it).
  4. No impact: An example is: if a network connection becomes available and your device connects to it. Also, when you plug your device in for charging, no alert or call to action step is necessary. It will probably do its job while you continue using your application.

Thus, depending on the interruption you are testing for, understand the behavior, and see if your application satisfies it.

Also, the behaviors described above need not be the same for all applications and devices. Be sure to find out specific details about your particular Mobile App.

Now that we understand what Interrupt Testing is and what to validate when conducting it, it is time to talk about how to do it.

How to Conduct Mobile Interrupt Testing

Look at this scenario: Google Chrome or any browser app for that matter has to run in the background when the user receives an incoming phone call.

Would you not call this a functional requirement of the google chrome app? I know, I would.

So, Interrupt Testing is a subset of Mobile Application Functional Testing. And, to conduct Interrupt Testing, you would follow the same Mobile Application Test Frameworks and Tools. It is the skill of the tester to conceive these scenarios. Once done, you would design the test cases and execute them in the same way as any other test. And do not get confused with the interrupt testing with the recovery testing. The recovery Test is to validate the restoration from a failure. Interrupt Testing is not necessarily a failure. It is a mere distraction.

The need for interrupt testing with various scenarios is very much necessary in this mobile app enriched world where competition between similar apps is at its peak. The best app with excellent usability is always talked about, referred to, and chosen by users.

Need help with your mobile application testing requirements? Trigent’s experienced quality assurance and testing team ensure your product is market-ready within stipulated timelines.

GPS Programming in Android for Offline Maps

Most mobile users and several developers may not be aware of the fact that GPS navigation is possible without Internet connectivity, i.e. ‘Offline map usage’ is possible without accessing the Internet!

Given below are a few tips on how to make this work and understand where offline data is stored:

To access maps, offline, i.e. when you are not connected to the Internet, you have to store the map tiles in your device and the code will render the map from the locally stored tiles’ information. ‘Tiles’ is the file which is in .zip or SQL format which will have all the information with respect to routes – latitude and longitude. All the map related files can also be stored in SD Card or device memory based on requirements.

In case you do not want to utilize your device storage for storing entire world map related data, the solution is simple. Download an application which is developed using some libraries that will download tiles and store files in device storage based on your selected region.

If you are an Android app developer and want to understand the process behind offline map application and if you also want to know the most feasible method to develop this kind of application, the answer is, there are a lot of libraries available and most of them are open source.

Given below are a few suggestions on open source libraries:

OSMAndroid :

Osmandroid is a tool which is used to show data from Open Street Maps when on-line, and can use tiles for off-line access. This is a raster-based option, and you can use Mobile Atlas Creator to create tiles from pretty much any WMS service.


MapsForge :

This is an excellent library for rendering OSM data on-the-fly or when needed, which means it will download the tiles based on the region. It has a special optimized tile format, and the rendering performance is quite good.


ArcGis Runtime for Android :

ArcGis seems to be oriented towards showing ArcGIS Server’s Mapservices. ArcGis can show data in an offline mode, by storing tiles in the compact cache storage format, or by using tile packages.


Nutiteq :

This is a fully featured library and includes several unique features such as support for 3D, various OGC services, custom Map API’s, offline routing and maps in any projection.


Google Maps Android API :

This is the default mapView in Android, and it uses the data from Google Maps. While the Google map application itself can be used in offline mode, as far as my knowledge goes, it is not possible to use Google Data in the offline mode. However it is possible to show your own tiles in offline mode.


MapBox :

This company has recently released an Android SDK, which can be used for online and offline maps.


To summarize, I have provided some information on libraries you can use for Android app development. These are the most popular open source libraries/tools for implementing offline maps. There are several other paid libraries and end-to-end solutions for implementing offline maps.


Listed below are some of the best offline maps available in Google Play Store:




This blog with basic level information and referral links is for curious developers who want to understand how offline maps work.  If you have any questions, do write to me at:

Rooting process in Android phones: Do you get more than you lose?

For a normal user, Android looks straightforward and simple. However, most users may not be aware that rooting is a process in Android which allows users to attain privileged control over various Android subsystems.  To simplify, rooting is a prison break in Android which gives the user control over the device. With this control, akin to administrative rights, one can customize an entire Android OS on the device, based on requirements.


  • Rooting can help in achieving great power for speeding up a device and can also boost battery power.  It is definitely advantageous if the right apps are installed, i.e. certain apps that can actually automate hibernation of unused apps which are running in background.
  • It can also be used to block ads.  There are possibilities of apps which display ads and these ads access and drain mobile data without one’s knowledge.
  • If a phone is stuck with outdated OS and manufacturers have no plans to upgrade or they take ages to send update via OTA, my advise is to get it rooted as there are various groups of ROM developers, ready to launch latest updates as fast as possible. These ROMs can  provide from basic  to high-end levels of customization in Android.
  • Rooting can have customized ROM running in devices which can change  the complete look and feel of  the device, enhance user interface and offer better features. This in turn can help to discard existing boring UI and transform it into rich UI.  For instance,  the regular keyboard which you get in a device can be given a theme of your choice, you can boost up the scrolling speed. To summarise, you can do anything and everything imaginable in terms of customizing. One of the most popular ROMs today is called CyanogenModbe, found in OnePlus devices .
  • Most of the phones these days come up with many unwanted and unused apps, which might be using more space and/or are not that great with UI. For those of you who have low memory space on the device,  rooting will be of great help as it can transfer the apps from internal to SD card. However there are some apps that can provide you with the option to move to SD card without getting it rooted.


  • If rooted, there is a high risk of missing  over-the-air (OTA) updates for the device. And, in case if you find any notification for OTA update its better to not upgrade as you might lose your power in root access.
  • Rooting your device is perfectly legal, but in most cases it is going to mean that your phone is no longer covered by its warranty. Thus, if you need to get your device serviced, you will need to  un-root your device. However, you would be wise to check on this before embarking on your journey.
  • There is a huge risk in  the device getting bricked, which means the device will have lesser functionalities though this might not harm the device. It is always better to do a soft-brick of device, so that it can be completely recovered in case of any error in rooting. Hard brick is not recoverable.
  • You might run the risk of inviting malware into the device, as acquiring root access can easily breach the security placed by Android OS. If an antivirus is not installed onto the device there are chances of gettingthe root infected with spyware, trojan, worms and viruses. You might thus end up losing your private data, be it your contact list, text messages or email. This can even go  up to the level of losing confidential data such as credit card information, password and username.


To summarize, you can definitely get more from rooting but it comes with a price. Now that you have an idea on what rooting does to your phone  it is up to you to decide. If you think that rooting the phone to run special applications and custom ROM is worth it, go ahead. If you think it is not worth the hassle, then my advise is, `don’t take the risk!’. At the end of the day, it depends on your usage and what you want from your phone. It is always recommended to proceed with caution.  A backup plan is also advisable, no matter how high your level of expertise!

So, How Secure is Your Mobile App ?

It’s no surprise, today, we hardly find a business without mobile presence. No longer can businesses afford to become mobile agnostic. Mobility has made deep inroads from enterprise corridors to our daily lives.

Right now, somebody is hacking..

Right now, while I am writing this, there are thousands of online transactions taking place on mobile apps across the globe and at the same time, thousands of companies devising their mobility roadmap.

On the darker side, there are millions of hackers busy in hacking!  But on the opposite side, mobile security teams and companies are working their way out to do their best to tackle the situations!

Each day, the number of mobile apps are rising in biblical proportion across App stores.  But as the number of these apps rise, so are the numbers of hackers and a new story to back the latest hack.  Mobile App development is a fast paced process and the time to market an app should be very quick. A little late entry can make way for the competitors to capture the market quickly. At such fast paced competitive dynamics, developers and companies spend a lot of time in finalizing the Functionality, User Interface (UI), User eXperience (UX), Business logic, Performance, QA etc. At the same time, most of the people neglect security aspects of their mobile applications as most of the time the focus is on rolling out their app to the market in a shortest time possible.

When an app is released in the app store without due consideration to security, the results can be catastrophic.

We have recently published an article on our site that talks about all these security aspects. Here are some of the talking points:

  • Security aspects of mobile apps
  • Impact of not giving much importance to security and
  • Few minimal set of security measures to be taken while developing a mobile app.

How Secure is Your Mobile App?

We are also in the process of publishing a whitepaper on ‘Security in Mobile Applications’, which is an exhaustive paper covering all the security aspects related to mobile applications. You can expect that in next few weeks. Keep watching this space for the same!

Do you want to share something on this topic ? Please do not hesitate to share your views and comments to

How IBM MobileFirst can accelerate Apps development?

Because of the increasing demand for cross-platform mobile solutions and mobile development tools, several Mobile solutions providers sprung up during hay years of mobile application. However, each one had its own shortcomings like uncommon language for scripting, proprietary interpreters, and limited environment for development. This led mobile developers to compromise on costs, user experience and marketing time. It was then IBM MobileFirst (formerly IBM Worklight) came to rescue the forte of many.

IBM MobileFirst is based on ‘code once and run on multiple devices’ approach. It provides a standard based, comprehensive platform that includes IDE/SDK, mobile-middleware, private enterprise app store, strong security framework, management & analytics console. It currently supports iOS, Android, Windows and Blackberry platforms.

This software helps corporates to expand their businesses to mobile devices. It offers an open, advanced and more comprehensive platform for building, testing, running and managing mobile applications for tablets and smartphones. Thus, it reduces the cost of development and the time takes to market. Furthermore, it also improves the governance of mobile application and facilitates a secure atmosphere for mobile applications.

After IBM acquired the mobile platform product Worklight in Feb 2012, it has integrated this product into all of its products so as to provide a complete life cycle management solution. After acquisition, it was called IBM Worklight. But after their 6.3 version, they have renamed the product to IBM MobileFirst.

The standards based technologies used by IBM MobileFirst completely removes the usage of code translation, non- standard scripting languages, and proprietary interpreters. IBM MobileFirst can accelerate the business development by enabling the corporates to support several mobile operating platforms from an exclusive, shared code base; by easily getting connected and synchronized with enterprise data, cloud services and applications; by protecting mobile applications in a secure atmosphere; and by governing mobile application from a single point of control.  Without writing a single line of code, through the use of adapters it can provide secure access to internal services. Similarly unified push notifications and SMS made the developers work very easy. They can be used with just few lines of code. IBM MobileFirst internally uses Cordova (Formerly PhoneGap) cross mobile platform along with HTML5, JS and CSS for hybrid applications.

The IBM MobileFirst’s portfolio can help enterprises of any size to quickly expedite development tasks for multiple platforms at ease. It can be utilized productively to develop, connect, run and manage mobile applications for matching the security standards of any business to that of any global organization.

Have something to share on MobileFirst, write to me!

Internet of Things: The Era of Mobile Application Development

From a mosquito repellent app that produces a sonic sound to scare mosquitoes away or Smarthings’ smart home apps connecting your rooms, doors, kettle, refrigerators to Nike’s wearable sports gear, tightly integrated with your fitness routine or Google’s driver glasses — the flurry of killer apps are reshaping our daily habits. It is interesting to see how Smartphone apps are becoming control points for the “Internet of things” applications.

According to Gartner, the Internet of Things installed base will grow to 26 billion units by 2020. McKinsey found that the Internet of things has the potential to create economic impact of up to $6.2 trillion annually by 2025.
The numbers give us a glimpse of future and how mobile application development will become integral aspect of “IoT”. At Factory level IoT-based smart and innovative apps are being used to monitor remote site assets, manage Machine-to-Machine (M2M) and device connectivity across healthcare, manufacturing or supply chain domains. McKinsey estimates by 2025, 80 percent to 100 percent of all manufacturing could be using IoT applications to improve productivity, leading to a potential economic impact of up to $2.3 trillion.

Read our full report on cmswire

Exit mobile version