How to run an application with Database on Android?

Asked

Viewed 3,513 times

0

I’m starting my activities in the mobile world, and would like to build an application that uses Database for Android platform, an example application so I can move forward, I looked on the internet but it was not very clear to me how to implement for this platform. Could someone help me with some indication of how to perform this? If possible also, someone knows some link where you can clarify how Android treats handling Database on your platform?

  • Look at this one of mine reply in the Soen.

2 answers

1

Example of creating a database on Android using Sqlite:

public class FeedReaderDbHelper extends SQLiteOpenHelper {
    // If you change the database schema, you must increment the database version.
    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "FeedReader.db";

    public FeedReaderDbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTRIES);
    }
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_ENTRIES);
    }
}

Reference: http://developer.android.com/training/basics/data-storage/databases.html

In SQL_CREATE_ENTRIES you inform the SQL DML commands for creating tables, fields, changing and removing fields.

The method onCreate will be called when there is an interaction with the Sqlite database and the database has not been created yet on the device.

The method onUpgrade will be called when there is an interaction with the Sqlite database, the database has already been created on the device, but the application on the device has been updated and the database is in another version.

You can put several db.execSQL one below the other for creating a certain table, changing a certain field, as you prefer.

There is also the possibility that Android communicate externally through Webservices with a server that presents a database, such as Mysql, Postgresql, Mongodb (Nosql, document-oriented database) using Java, PHP, or other programming language to perform the communication, usually the REST architecture is used and returns JSON to the application.

Other useful links:

http://www.tutorialspoint.com/android/android_sqlite_database.htm http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html https://www.sqlite.org/docs.html http://json.org/ http://www.infoq.com/br/articles/rest-introduction

  • 1

    Important to note that in the case of remote bank the webservices are a necessary intermediary, more recommended than trying to establish a direct connection of android with the remote bank.

0

Good morning. If you want to create a database on an Android App. This will depend on several factors. First, the application runs on server-client aquitecture. or there’s no server communication, whatever cloud, and it’s stored in the phone’s database. Put simply, you need to know first whether the database is local or remote. then, I believe that the best way, at least the one that would follow, would be to create a Mysql database, or a Mongodb-style architecture (Nosql, therefore), and create variables in the Java part, which connect with the database and allow the respective data input. for sure, you will find countless github repositories with numerous database templates for Android, etc. if you want, however, you can choose to search on sites like Envato, codecanyon, and other online stores for similar solutions. Normally, the less you have to reinvent the gunpowder, the greater the productivity in the medium term. and there is always the possibility to refine your product in the medium term. as I say, at the beginning, the more you can simplify the implementation of your product, the better.

  • 1

    think also about the possibility of including code in ruby on Rails, Node. Js and angular.Js in your application. are very powerful and fast tools, and you can definitely find a lot of templates on github, about how to embed this in an android app. View the manual re-reference of each of these Apis/Frameworks, and take a look at some tutorials on youtube. youtube user Derek Banas has very extensive, comprehensive, and accessible introduction tutorials

  • Node and angular run in Javascript, so it won’t be a problem to include them in Java. as for ruby on Rails. I’m not sure, but it shouldn’t be a problem at all

Browser other questions tagged

You are not signed in. Login or sign up in order to post.