I am building a social media application which requires local storage of table data entities. This data must also be connected to a server to retrieve and update information to and from users. Our team has built an iOS client using core data, though we are looking for storage options in android. Is using SQLite the way to go? Any thoughts would be greatly appreciated.
You should take a look at Realm, it has clients for Objective-C, Swift and Android.
Description from their GitHub repository:
Features
Mobile-first: Realm is the first database built from the ground up to run directly inside phones, tablets and wearables.
Simple: Data is directly exposed as objects and queryable by code, removing the need for ORM's riddled with performance & maintenance issues. Plus, we've worked hard to keep our API down to very few classes: most of our users pick it up intuitively, getting simple apps up & running in minutes.
Modern: Realm supports easy thread-safety, relationships & encryption.
Fast: Realm is faster than even raw SQLite on common operations, while maintaining an extremely rich feature set.
If you're familiar with RxJava, you will probably want to check SQLBrite, wich is Square's solution for this.
Yes, Sqlite is a default storage solution for android. Howevere there is a wrap around it called ContentProvider. ContentProvider can be used with Loaders and provide async data loading. ContentProvider may be used to modify contats and merge accounts, see this guide. However ContentProvider may seem tricky and if you prefer ORMs you can use ORMLite or GreenDAO which are using sqlite as well.
Related
I am relatively new to app development and core data, so take it easy on me. I have been working on an app (currently for iOS, android in the future too) which stores the user's data locally using core data.
The data has relationships across entities. User can create, update, delete data.
Now I need to integrate some kind of syncing solution. My requirements are:
Data should be accessible offline (right now I am testing queue operations for that)
Data should sync to cloud storage when network is available (on iOS I have tested out reachability for this)
Cloud storage needs to be integrateble to both my current iOS and future android version.
Relationships (or some other way of linking parent-child, i talk about it later) need to be maintained.
Core data on ios should be used, not third party replacement.
I have messed around with many solutions so far:
I setup my own rethinkdb database on a server and used PHP and REST to get things going. This was very messy.
I tested parse.com and afnetworking http requests (instead of parse's library) - this was better, but i couldn't seem to be able to manage the relationships from core data. And my syncing algorithm is complicated (it works but I am not sure if there are holes in it when it may fail)
I tested dropbox datastore api. I have only tested the iOS sample app they provide, seemed pretty good (still need to understand the workings).
My questions are:
If I were to use dropbox datastore api, how does it work with android? of course core data is not available there, so how does that work (sorry I don't have android dev experience yet)? ALso how does it handle relationships between entities?
If I go with Parse.com, do you think my this idea will work-
Instead of using relationships, I can use identifiers? my relationships are all 1-to-many, so on the parent (1) I can have an id A. On all the children I can point their parentid to A. Also since my children can have grandchildren too, on each of the children I can have another id which the grandchildren can point to. So on... does this make sense as a replacement of relationships? If yes, then what's the point of relationships in xcode?? other than having automatic cascade option maybe.
Are there any better solutions available for syncing cross platform?
I know my question may seem a bit asking for opinion, but I would like to see what everyone else has already tried. Past week of switching from one solution to another and designing the syncing algorithm has fried my brain.
(I work at Dropbox and will address just that part of the question.)
The Dropbox Datastore API doesn't use core data and thus works exactly the same way on Android. Why is core data a requirement?
As to relationships, what you describe for Parse is exactly what I would suggest for use with the Datastore API. I believe you're right that the reason for modeling relationships in databases and in code is to get automatic cascading operations and enforcement of relationship invariants.
I am new to mobile app development and thus have a few questions.
Currently I am in a team that is about to develop an android mobile application for the Ice Cream Sandwich (4.0) operating system. This application will enable the user to fill out profile information which gets stored in a database that is not on the phone. However, since the database stores private information from the user, it should be private.
The purpose of the app is to utilize the user's profile information in conjunction with information of a geographic area (terrain, climate, flora, fauna) in the United States from an online database in order to calculate how well they will be able to survive for a given amount of time.
I am planning on using the Android development tools plugin with the Eclipse IDE.
So I wanted to ask a couple of major questions:
What will I use from the Java development tools to add users and enter in their profile information to the database? In other words, what will I use in order to communicate with the database?
Since the application will be pulling information from an online database, it will need some way of transferring and using that information. What can I use to do this?
Thank you,
Read up on SQLite support for Android and how to make HTTP requests:
http://developer.android.com/guide/topics/data/data-storage.html#db
There are a few libraries you can look into.
For database interaction (locally), ORMLite is nice. This gets you one step away from writing raw SQL, handles escaping for you, etc. It maps your database rows onto POJOs for you (as the name implies).
For the remote data, you'll want a REST (or SOAP? or ??) client. It isn't clear whether the remote data store belongs to you, or if so, whether you've created it yet. If it is already in place, you have less flexibility here.
The Spring framework offers a couple Android libraries including one for consuming REST services and one for authentication. I have also seen mention of people having success with Jersey.
If you do go REST, then you will (probably) be dealing with JSON. Jackson and Gson are the two main contenders here. Both offer automatic (de)serialization between POJOs and JSON. I've used Jackson, and I will probably try Gson the next time around. While Jackson is nice, I found the documentation to be a bit fragmented and hard to follow. Ymmv.
My latest project uses a combination of ORMLite, Spring's REST library, and Jackson to pretty good effect.
The gist is this: define some model classes, annotate the classes and their fields with a few things from Jackson and a few others from ORMLite, point Spring at your endpoint. Spring will retrieve the JSON, Jackson will parse it into model objects, and you can then use ORMLite to persist it to your local database. In the other direction, pull something out of your database (ORMLite hands you model objects), hand the model off to Spring, which uses Jackson to serialize the data before sending it out.
For both 1 and 2, you can develop web service that will allow android application to communicate with Remote database to either insert or retrieve or even delete records from database.
and here is a good Tutorial to give you clue how can you start doing so.Click Here Please
I have been searching and have found out, that android supports only SQLite databse and no other. Is this true?
Yes. The Android library provides native support to only SQLite. Of course, this doesn't mean you absolutely can't use other databases on Android; if you need to use other databases, you'll have to either look for already-existing third-party libraries(1), or roll out your own API.
(1) Careful there: If you look for third-party libraries, make sure they're built specifically for Android, since Android includes only a subset of the Java standard library. If they're not specifically built for Android, there's a possibility that the libraries won't work due to missing classes.
Yes, Android Supports H2 Database too. please check it out with below link,
http://www.h2database.com/html/tutorial.html#android
Thanks,
Though SQLite is natively supported on Android and is most used database, there exists other options as well. Listing a few of them below;
Realm:
Reactive, concurrent, and lightweight, allowing you to work with live, native objects.
https://realm.io/docs/
H2:
Full Unicode support including UPPER() and LOWER().
Streaming API for BLOB and CLOB data.
Fulltext search.
Multiple connections.
http://www.h2database.com/html/tutorial.html#android
CouchDB:
Full CRUD and query functionality, NoSQL, lightweight, embedded, syncable
https://developer.couchbase.com/mobile/
LevelDB:
Lightweight and single purpose (not an SQL database)
http://leveldb.org/
Java wrapper: https://github.com/hf/leveldb-android
I am not including BerkeleyDB here as (AFAIK) it needs OS level changes to be made to replace the SQLite routines. More info here https://blogs.oracle.com/berkeleydb/now-you-can-build-berkeley-db-into-your-android-apps
SQLite is the only one I ever actually see being used. I would suggest using it because it is lightweight and free to use. When developing your App, lightweight is key, memory is limited on these devices! Is there any specific reason why you wouldn't want to use SQLite? Any feature that you're looking for that you don't see in SQLite?
I'd like to use myBatis (iBatis 3) in an Android application. Has anyone tried such a thing or know of any resources for this?
aBatis is a data mapper framework available for Android
that couples objects with stored procedures or
SQL statements using an XML descriptor or annotations.
aBatis is like an Android equivalent of iBatis.
---simple & light ORM library like iBatis for Web development
--carrying ibatis's feature
--easy-to-use as iBatis
--shorten a development period
--independent of development phase
--Android sdk1.6 and up
http://sonixlabs.com/abatis/
The first thing to do in order to do that is to compile myBatis for Dalvik. But it's likely to be too heavy for a device like a smartphone.
If you are looking for a lightweight persistence layer, you could look at Ammentos:
http://www.ammentos.org/
Same trouble: you will need to compile it for Dalvik.
Existing ORMs for Android:
http://ormlite.sourceforge.net/sqlite_java_android_orm.html
https://www.activeandroid.com/
It's better to use lightweight lib in android apps like greenDAO or Ormlite, greenDAO is an open source project to help Android developers working with data stored in SQLite. SQLite is an awesome embedded relational database. However, developing for it requires alot of additional work. Writing SQL and parsing query results are quite tedious tasks. greenDAO will do the work for you: it maps Java objects to database tables (often called ORM). This way you can store, update, delete, and query for Java objects using a simple object oriented API. Save time and focus on real problems!
greenDAO’s primary design goals
Maximum performance (probably the fastest ORM for Android)
Easy to use APIs Highly optimized for Android Minimal memory
consumption
Small library size, focus on the essentials
I create simple android project that using mybatis
check this: https://github.com/gustaroska/HijrDroid
Are there any good database abstraction layers/object relational mappers/ActiveRecord implementations/whatever they are called for Android? I'm aware that db4o is officially supported, but it has quite a large footprint and I'd rather use a more conventional database (SQLite).
I am the main author of ORMLite which was designed to be small[ish] but still provide higher level functionality. ORMLite makes calls to the native Android OS database APIs to support its ORM functionality. See the following for general information
http://ormlite.com/sqlite_java_android_orm.shtml
Here are some Android example applications:
http://ormlite.com/docs/android-examples
I tried the Sugar ORM, which is very basic (and easy to use) but it worked for my needs.
Sugar website
There is an 'android-active-record' project which provides ActiveRecord abstraction for accessing Android SQLite database.
It's available here: http://code.google.com/p/android-active-record
It allows to eliminate most of boilerplate coding when performing CRUD operations on database entities and also minimizes efforts for creating/maintaining a database structure
Try ActiveAndroid. It is free and open source (Apache Version 2.0).
From the website:
ActiveAndroid is an active record style ORM (object relational
mapper). [...] ActiveAndroid allows you
to save and retrieve SQLite database records without ever writing a
single SQL statement. Each database record is wrapped neatly into a
class with methods like save() and delete().
[...] Accessing the database is a hassle, to say the least, in Android.
ActiveAndroid takes care of all the setup and messy stuff, and all
with just a few simple steps of configuration.
If performance and size matter, you should have a look at our open source ORM tool greenDAO. We wrote it because we did not want to compromise on speed. Other tools heavily rely on reflection, which is very slow on Android. Despite the tiny size (<100k), it supports relations, query builders, etc.
Shameless plug, but I've been working on a new open source Android framework called Infinitum. One of its main features is an ORM which has a criteria API similar to Hibernate and a few other nifty features (associations, lazy loading, etc.). It's still in its early stages, but I think it's coming along pretty nicely.
I have written a new ORM, for android, that's aimed and being as easy as possible to implement. It support lists and SQL free migration a couple things which I always found had an overhead in other libraries.
http://www.rushorm.com/
I faced the same problem and looked at both android-active-record and ActiveAndroid. I found android-active-record didn't handle the things I cared about (relationships for example), and ActiveAndroid isn't free. Therefore, I decided to write my own library. It's called AndroidRecord and it's hosted on GitHub and you're free to do with it what you want (I think I'm going to go with the MIT license). I use this every day and I'm content with it, but I'd love to get feedback.
If you need to know how to use it, I'm working on the documentation. If you need it right away, you can check out this lame example project which should be enough to dip your toes in. You can also email me of course.
There's also Neodatis and Perst (Lite).
I've toyed with Perst a year ago and concluded it's not worth it.
After all, a) Android runs on a rather restricted device with ~16mb of heap space per app and b) You customers would really appreciate performance and low power consumption.
So my advice is to go with SQLite and hand-written SQL. It's not hard at all and the wrappers provided by Android SDK are really nice.
EDIT: In 2012 the advice would be to use the ORM component of DroidParts (which is my project).
I was comparing basics of ormlite and greendao some time ago. You might want to take a look there. I plan to write some follow up with more advanced stuff in the near future but for now it's only a basic stuff. In my own project I'm using GreenDAO.
Have a look at Androrm. It is open source and well documented (see here). If you ever worked with django, you will notice, that the syntax is very similar.
Androrm also supports abstraction classes for the most common field types, plus relational fields. This way it enables you to query for your data in an very easy manner with only very little effort on your side.
SQLite is explicitly part of Android:
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
However you might have to create your own abstraction layer (query builder for simple queries), or otherwise deal with SQL.
Maybe http://developer.android.com/reference/android/database/sqlite/SQLiteQueryBuilder.html is what you need?