Android Debug Database: A Library for Debugging Android Databases and Shared Preferences

Android comes with a powerful built-in database called SQLite, but it doesn't come with the best set of debugging tools. When it comes to debugging databases in an android application, it is very difficult to see what’s happening inside the database. The same is true with Shared Preferences. In fact, unless you have a rooted device, you can't even get the SQLite tables off your device without jumping through some hoops.

Android Debug Database

Android Debug Database is a powerful library for debugging SQLite databases and Shared Preferences in Android applications. It allows you to view databases and shared preferences directly in your browser in a very simple way.
By using the Android Debug Database we can do the following:
  • See all the databases.
  • See all the data in the shared preferences used in your application.
  • Run any sql query on the given database to update and delete your data.
  • Directly edit the database values.
  • Directly edit shared preferences.
  • Delete database rows and shared preferences.
  • Search in your data.
  • Sort data.
  • Download database.

Android Debug Database Library in your application

Let’s take a look how we can implement it into our Android applications and debug the SQLite databases and shared preferences.
Complete source code for the examples used in this tutorial is available on github.

Creating New Project

We’ll start by creating new project in Android Studio and do the basic setup required.Create a new project in Android Studio from File > New Project and fill the project details.

Update Build Configuration

Open build.gradle located under app module and add android debug database dependency.


Create SQLite Database Handler Class

Create a new class in your project src directory and name it as DatabaseHandler.java ( Right Click on src/package > New > Class)
Now extend your DatabaseHandler.java class from SQLiteOpenHelper.


Insert Records

Update MainAcitvity.java file to create the instance of DatabaseHandler.java class and add some rows.


Store Data Using Shared Preferences

Another way of storing data of an application is called Shared Preferences. Shared Preferences allow you to save and retrieve data in the form of key,value pair.
Create a Shared Preference instance and store some values.


Debugging Databases and Shared Preferences

Now we can debug the database and shared preference used in the app with the help of a web interface.
To do that do the following steps:
  • Your Android phone and laptop should be connected to the same Network.
  • If you are using it over usb, run adb forward tcp:8080 tcp:8080
Start the application, you will see in the logcat an entry like follows :
If you want use different port other than 8080. In the app build.gradle file under buildTypes do the following change :


Seeing Sqlite DatabaseScreen Shot 2017-04-12 at 10.25.16 PM-min.png

Editing ValuesScreen Shot 2017-04-12 at 10.25.35 PM-min.png

Run Sql QueryScreen Shot 2017-04-12 at 10.26.47 PM-min.png

Seeing Shared PreferenceScreen Shot 2017-04-12 at 10.26.19 PM-min.png



Comments

  1. Thanks for sharing Information to us. If someone wants to know about,I think this is the right place for you!

    Mobile App Development in Coimbatore
    Mobile app development company in atlanta
    3D Animation Company

    ReplyDelete
  2. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    web designer course in chennai
    web design development training in chennai
    web designing course with placement in chennai
    web design and programming courses in chennai
    web design and development training in chennai
    web designing courses in chennai
    web designing training and placement in chennai

    ReplyDelete
  3. Thank you for sharing this! What you have shared is very helpful and informative. Would love to see more updates from you.

    Melbourne Web Designer

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Use Kotlin in Your Android Projects

Reactive Programming with RxBinding

Getting started with Android Fingerprint Authentication

Introduction to Spring Animation

Exploring Android O: Autosizing TextViews

Exploring Android O: Fonts in XML

Kotlin: Do more with less code

Introduction to Android Bottom Navigation View

Picture-in-Picture: Working in Android Oreo