Managing an Android database - android

I'm looking to implement my first Android database, but I have so many questions which (I believe) are unanswered by all the tutorials I find.
Here are my needs:
- I want my application to have a database that is persistent. If my application closes and launches again, there is already a database to pull data from. It does not create a new database every time the application is killed and re-launched.
- I want to implement versioning. Say version 1 of my application has a few tables. I release version 2 and I want some sort of script to run to add new tables I've added or modify old tables I've added; and so on and so forth. The application has to know whether the database is at a particular version (which means I'll need a table in the database) so it knows whether to run this script.
Could someone provide me with some resources so I can figure out how to do what I need? Thank you

Look for sqlite+android+tutorial:
http://www.hdelossantos.com/2009/12/23/creating-a-sqlite-database-in-android/
http://www.hdelossantos.com/2010/01/07/using-a-sqlite-database-in-android/
and some more:
http://www.google.com.hk/search?sourceid=chrome&ie=UTF-8&q=android+sqlite+tutorial
There is also a sample in the sample programs that come with the SDK, i.e. the Notepad app.
And the official developer api doc - but that's more as a reference, not as tutorial:
http://developer.android.com/reference/android/database/sqlite/package-summary.html

Related

how BoxStoreBuilder.usePreviousCommit works internally?

i converted my android app from mapdb to objectbox, i've seen on github a few people reporting database corruption with objectbox and the solution has always been to call usePreviousCommit in case of problems.
since the objectbox core is close source I wanted to know what usePreviousCommit does internally
are there 2 physical copies of the database? and calling usePreviousCommit reverts to the previous copy?
or does it work in a more complex way? (if yes i wanted to know how)
i opened this question because i want more information from objectbox before i continue to use it in production.
The key word is multiversion-concurrency. Think of a B+ tree with copy-on-write. The previous root tree (aka the previous commit) is preserved, so you can use when opening.

Room database in a Android library and Objects and Dao's in Android project

I want to implement Room database in my app, but I want to do that by creating a Library project.
Library project will store data
Android project will have the Objects and Dao's
Is this possible?
For this I have to implement Room in both Android project as well as Library
But can I have Dao's and Objects in Android project and Database in Library
Why I want to do this.
I want to build this feature in a generic way so that it can be used in my other project. Also Library will not just store the data, it will have some offline functionality which read a Offline data table and checks the internet connection and picks data from the table and send it to server.
None of this is implemented yet. I am in the process of thinking what is the right aproach
Thanks for your suggestions
R
It's a great desire to move Room to the separate module as far it's Android specific and violates the principle of the Clean Architecture. Here is where you can start, at least it looks similar: another stack question and take a look at all the answers.
About re-usage, probably, it will be quite hard. Not sure, that time you spend to make it universal be less than when you implement it in each project. So, take the time in the account also.
The case where it makes sense.
At my company, we did the next. We have a few related products (a few apps) that have similar user-intended logic. So we have a library that takes care of all user login / token expiration logic and so on and it provides a simple interface for the app to handle user account. Single code base, useful when fixing bugs. And connect this library to each project as a general module. But still, each app has its own internet communication and database because of domain-specific data.
The best for testing and architecture - move all room and internet logic to the module in the app. Access it by interfaces. You can share that module between apps.
I think you can use dynamic feature module, because it dependency to the app module and you can use Dao and Objects from app.

Migrate sqlite database from android studio app to Xamarin.Forms app

I've been developing an android app for the last year or so in android studio. It has been in the play store since October and quite a few people are using it.
I have received many requests to create the same app for iOS and so after a lot of research I've settled on xamarin forms as it will be easier to code (as I'm familiar with c# and xaml) and less work to maintain the app for both platforms at the same time (even though it will take a while to port the code over).
The android app is using sqlite for data persistency and the xamarin version will do the same.
My question is, how could I port the sqlite databases of existing users to the new app once it is released? Is there a way to define the table/column names the same as I have set them in the android studio version?
Currently the app has a feature to export the database to the Downloads folder and the xamarin.forms app will import it from there.
I haven't seen anyone in any tutorial explicitly define the table and column names in their xamarin.forms sqlite implementation so I'm a bit worried to take the leap.
Is there a way to ensure that existing databases will work out of the box once imported in the xamarin.forms app? If not, could someone please point me towards a piece of code that will migrate data from one dB to another?
Thank you in advance for your time.
Regards
As I got a bit more familiar with the SQlite package in Xamarin.Forms, turns out that the answer is as simple as adding the [Column("my_column")] attribute above the property in the model. This way it will name the column to whatever is specified in the brackets and I can make sure it matches the database schema I have in my current project from Android Studio.
a bit of a "duh!?" moment here for me but thank you to all who have taken the time to answer!

Android Room: Replace existing schema (migrations and all) with a new one?

I've been messing around with an Android project that uses a room database. Because I didn't design the database before I started (I didn't initially plan to even use one), it has a bunch of migrations that drop and recreate tables all over again.
I've never released the app since it's kind of a learning project, but if I ever show anyone I'd rather not show them the 3 migrations in a row where I drop and recreate the table. Is there a way just to tell it to use a completely new schema, as if it had never used one before?
Turns out I hadn't been wording my Google searches properly. I should have searched for how to reset to version 1 since that's a lot clearer than dropping tables or schemas.
See this stackoverflow link below to see what answered my question:
Room persistent library reset version to 1

Realm databases and compatibility between different schemas

I am creating Android app and need a way to store data and sync with server so i have posibility to have access to the same data from different devices and places. I am consider using Realm Database. I think that it will match all my requirements. But i have one question. Let assume that we released version 1.0 of our application, few users have access to one realm (lets name it REALM-ONE), they are making changes there(insert, update, delete). In meanwhile we developed a next version of our app with a little changed schema, i mean we add one property to the object and make a breaking changes in another(e.g. merge two properties into one and change data type). Part of the REALM-ONE users updated app to the newest version(other users cannot because of too old version of android), and i want everyone to have opportunity to still using the REALM-ONE as before without need to update app. Quick diagram:
According to docs i know what will happen with new property, it will update on server and be visible in v2.0 but surely should not be visible for previous version of the app. And what with breaking changes ? Can i support this change in v1.0 ? Can it still collaborate together ? Can I managed it with realm notifications or realm functions ?

Categories

Resources