Skip to content

Instantly share code, notes, and snippets.

@myanmarlinks
Created July 11, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myanmarlinks/e5c4981b0ed1320955060f29f7792bf5 to your computer and use it in GitHub Desktop.
Save myanmarlinks/e5c4981b0ed1320955060f29f7792bf5 to your computer and use it in GitHub Desktop.
Awesome Realm - MainActivity
package net.myanmarlinks.awesomerealm;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import net.myanmarlinks.awesomerealm.model.Author;
import net.myanmarlinks.awesomerealm.model.Category;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import io.realm.Realm;
public class MainActivity extends AppCompatActivity {
private Realm realm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
realm = Realm.getDefaultInstance();
List<Category> categories = new ArrayList<>();
List<Author> authors = new ArrayList<>();
categories.add(new Category(getUniqueID(), "News"));
categories.add(new Category(getUniqueID(), "IT"));
categories.add(new Category(getUniqueID(), "Breaking News"));
authors.add(new Author(getUniqueID(), "Aung Aung"));
authors.add(new Author(getUniqueID(), "Baung Baung"));
authors.add(new Author(getUniqueID(), "Hla Hla"));
realm.beginTransaction();
realm.copyToRealm(categories);
realm.copyToRealmOrUpdate(authors);
realm.commitTransaction();
}
private String getUniqueID() {
return UUID.randomUUID().toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment