Managing Android apps' SQLite databases is tough while developing. You cannot view the tables, you don't know what is getting inserted into the tables and you can't update the data and see how your application responds to it.
-
Clone or download this repository and add AndroidDatabaseManagerTool.java file to your application.
at lines 54 and 73 change yourSqlliteopenhelper to the class name of your custom SQLiteOpenHelper class i.e, the class which you are using to create tables, insert data to your app SQLite database.
After changing the name, some errors will exist! don't worry, they will be gone after the next step.
-
Open helperFunction.txt file copy the entire text and paste the function in you custom SQLiteOpenHelper class .i.e, the class which you are using to create tables and insert data to your app's SQLite database.
If there is a compile error at
MatrixCursor
, addimport android.database.MatrixCursor;
statement at the start of your class file -
Add the following code to your android manifest .Enter the name of the package where AndroidDatabaseManagerTool.java is located.
-
Now you have to start the AndroidDatabaseManager activity . You can do this anyway you wish,Below 3 are the simple ways to start the activity choose anyone as per your convenience.
(i) add OnClickListener to a TextView. You can use the textview which is already present in your layout or add a TextView element to your xml.
TextView tv =(TextView)findViewById(R.id.yourtextviewid); tv.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent dbmanager = new Intent(getActivity(),AndroidDatabaseManager.class); startActivity(dbmanager); } });
(ii) add OnClickListener to a Button. You can use the button which is already present in your layout or add a Button element to your xml.
Button button =(Button)findViewByID(R.id.yourbuttonid);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent dbmanager = new Intent(getActivity(),AndroidDatabaseManager.class);
startActivity(dbmanager);
}
});
(iii) If you are using an action bar add an item to the action bar and start activity when action bar item is clicked.
That's it. Now you can manage your application database directly from your app.
When app development is done remove the activity and publish your app.
With this library you can do all these :
1) View all your tables data in tabular format
2) Insert rows to your tables
3) Update rows
4) Delete rows
5) Delete tables
6) Drop tables
7) Write your own custom queries and view the results. (Create statements, joins, etc)
8) Change data in the tables and see how you application responds
In a nut shell, you can manage your app database easily.