This Question have 3 answers right now.

How to seed a Realm database with standard data?

Question!

I'm working on a basic project for fitness tracking. I want to initialize the app with an exercise library prepared for the user. How do you provide the data and set up the transaction to populate the database? I've seen the answer below, but I can't find how to actually set up the example, defined in the answer as MyInitialDataRealmTransaction.

Thanks in advance for any insight.

How can I create a Realm database with initial data for my android app?



Answers

The initial data takes a transaction as a parameter which runs if the Realm was first created or the Realm was deleted because migration was needed and the config for that was set.

Here is a basic example.

public class RealmInitialData implements Realm.Transaction {
    @Override
    public void execute(Realm realm) {
        Book book = new Book();
        book.setId(1);
        book.setAuthor("Reto Meier");
        book.setTitle("Android 4 Application Development");
        book.setImageUrl("http://api.androidhive.info/images/realm/1.png");
        realm.insertOrUpdate(book);

        book.setId(2);
        book.setAuthor("Itzik Ben-Gan");
        book.setTitle("Microsoft SQL Server 2012 T-SQL Fundamentals");
        book.setImageUrl("http://api.androidhive.info/images/realm/2.png");
        realm.insertOrUpdate(book);

        book.setId(3);
        book.setAuthor("Magnus Lie Hetland");
        book.setTitle("Beginning Python: From Novice To Professional Paperback");
        book.setImageUrl("http://api.androidhive.info/images/realm/3.png");
        realm.insertOrUpdate(book);

        book.setId(4);
        book.setAuthor("Chad Fowler");
        book.setTitle("The Passionate Programmer: Creating a Remarkable Career in Software Development");
        book.setImageUrl("http://api.androidhive.info/images/realm/4.png");
        realm.insertOrUpdate(book);

        book.setId(5);
        book.setAuthor("Yashavant Kanetkar");
        book.setTitle("Written Test Questions In C Programming");
        book.setImageUrl("http://api.androidhive.info/images/realm/5.png");
        realm.insertOrUpdate(book);
    }

    @Override
    public int hashCode() {
        return RealmInitialData.class.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return obj != null && obj instanceof RealmInitialData;
    }
}


From here

Something like this should work to allow User1 to only access User1's folder:

{
 "Version":"2012-10-17",
 "Statement": [
   {
     "Sid": "AllowUserToSeeBucketListInTheConsole",
     "Action": ["s3:ListAllMyBuckets", "s3:GetBucketLocation"],
     "Effect": "Allow",
     "Resource": ["arn:aws:s3:::*"]
   },
  {
     "Sid": "AllowRootAndHomeListingOfCompanyBucket",
     "Action": ["s3:ListBucket"],
     "Effect": "Allow",
     "Resource": ["arn:aws:s3:::my-company"],
     "Condition":{"StringEquals":{"s3:prefix":["","/"],"s3:delimiter":["/"]}}
    },
   {
     "Sid": "AllowListingOfUserFolder",
     "Action": ["s3:ListBucket"],
     "Effect": "Allow",
     "Resource": ["arn:aws:s3:::my-company"],
     "Condition":{"StringLike":{"s3:prefix":["user1/*"]}}
   },
   {
     "Sid": "AllowAllS3ActionsInUserFolder",
     "Effect": "Allow",
     "Action": ["s3:*"],
     "Resource": ["arn:aws:s3:::user1/*"]
   }
 ]
}

Apply that as User1's policy, and they should only be able to access the user1/ folder. The "s3:prefix":["","/"]... part can probably be changed, but I'm not familiar enough with the policy language to know how.

If you substitute user2 for user1 in User2's policy, User2 should only be able to access the user2/ folder, and so on.

By : millinon


If I am reading this correctly, Message would contain a List<MessageUser>.

If that's the case then this should get you close:

var List<Message> messages = 
    ( from m 
      in db.Messages 
      where 
          m.UserID == userid || m.MessageUsers.Any(mu => mu.UserID == userID) 
      select m).ToList();
By : Sam Axe



Android Realm storing int[] and String[]

Realm : How to structure one to many relationship

Get diacritic insensitive results from Realm database query

Using Reserved names with realm.io / Android

RealmProxy error on Realm Object

how write queries in the RealmList?

Null Pointer exception in Realm

Realm - Share Database between Apps

Android Realm Retrofit relationship error

How to edit data before to storing into database Realm

Saving realm relationships does not persist them

Class relationship, NullPointerException error

How do you check if a realm instance has been closed already?

Android Realm: compactRealmFile NullPointerException

Video about How to seed a Realm database with standard data?