Accessing multiple realm databases simultaneously - android

I have two users who have made realm databases. User1 has given admin access level to User2. Both create a list of objects. How can User2 get a list of objects made by himself and User1?
Currently User2 can access only 1 realm database on signing in.
I am using android.

If you are having two db, means you have two RealmConfiguration, one for each. You can get the realm appropriate db by calling Realm realm = Realm.getInstance(realmConfigurationInstance). Whichever, configuration you will pass, you will get that instance of the db.

Related

Sqlite database with android - local?

I have an android app that I have been working on and I created a sqlite database using the android.database.sqlite package. I know that you can access that data by using Android Studio manually, but I am trying to save data into the database so that if one user of the app does something to add to the database, another user of the app will have the same access to the database. Will the android.database.sqlite package allow this or will the database for each user be unique to that user? If this is the case in which all users cannot access the same database after updating, what is the best way to go about creating a database that would let every user access it even when updates occur?
It is possible to add multiple users to a local application. Here is the simplest way to accomplish this:
1) Create a table for users in your database, with a user ID
2) Every user specific value in other tables should be marked to corresponding users with this ID
3) When you fetch the data from database, use the Select statement specifying user
Tip: Android has an Object-Relational-Mapping Library called Room for making database creation simpler. Reading about Room would help too! Take database classes for gaining knowledge about such common tasks.

Send data to Realm object server from app

I am creating an Android application in which I am using the Realm database to store data, and I am using the Realm object server to login and register user. I am able to log a user in using SyncUser and I am able to see that my login user has been stored in the Realm object server.
But now I have additional fields that I want to store - for instance, mail and age. I know how I'd store it in a different database but I don't know how to do this in Realm.
If you are talking about storing metadata about a user. That is not supported yet, but will be added soon. You can follow https://github.com/realm/realm-java/issues/4645. For now the workaround would be to save them in your own custom User Object.

data sharing between two realm users

I am developing a project in which I am trying my hand on Realm.
Its auto syncing functionality is awesome but now I want to share data between two realm users.
So Scenario is: Say I have two users "A" and "B", When "A" update anything in table "X" then "B" should be able to see those changes, so basically they both are dealing with the same table and not two realms.
If this is not possible than I have heard/read about realm functions, So by using functions can we add/update B's realm whenever "A" update his realm with the same data?
Letting multiple users work together on a realm is one of the use cases for Realm Object Server. You can use android demo app as a starting point.

Prefilled realm object server database

Is it possible to keep initial version(prefilled) of realm database to Realm Object Server which will be synchorized once user authorized first time?
Then users will be able to read/modify their copies. It is not multiediting - every user has it's own database, just prefilled from a server.
Yes, you can. You can setup a Realm function that monitors either when the user is created or when they access the Realm for the first time, and then let the server fill the Realm.

Combining two realm databases of the same realmobject from android wear to phone

I'm a self taught android programmer so sorry if this is a newbie question. Does anyone know if there's an easy way to merge two realm database files into one combined realm database? The databases contain the same realmobject types and are mutually exclusive (no overlaps of identical objects).
My goal is this: I have a realm database of a workout "session" that is comprised of a list of objects that the user adds to using a wearable. When the user saves the session, I want to send those saved objects to the phone where it can be combined with all past sessions in a realm database stored on the phone.
I'm able to send the database file from wear to phone as an asset and simply replace the file on the phone (using this sample code https://gist.github.com/tajchert/dc30560891bc6aee76fb), but it seems wasteful to send the entire database every time, and I don't want to lose everything if the wear database gets deleted somehow. I'd rather save only the new data from the current session and then clear out the database on the wearable when a new session is started. That way, I'm only ever sending new data to the wearable data layer.
In general, it is not possible to move Realm objects between Realms. You can use copyFromRealm() and copyToRealm(). Of course, you will need to keep track of which objects, which are already been moved (either my marking them somehow or deleting them).
Another option is to use Realm Mobile Platform (https://realm.io/products/realm-mobile-platform/) which can help you to keep all your devices in-sync.

Categories

Resources