Created
July 19, 2016 08:32
-
-
Save leeyc09/f0d7bcfbd4522e09394dc8de960fc5b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Activity */ | |
package jiran.com.myapplication; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import io.realm.Realm; | |
public class MainActivity extends AppCompatActivity { | |
Realm mRealm; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mRealm = Realm.getDefaultInstance(); | |
mRealm.executeTransactionAsync(new Realm.Transaction() { | |
@Override | |
public void execute(Realm realm) { | |
realm_test realm_test = realm.createObject(realm_test.class); | |
realm_test.setId("1"); | |
realm_test.setLogin_id("2"); | |
} | |
}, new Realm.Transaction.OnSuccess() { | |
@Override | |
public void onSuccess() { | |
Log.d("AA", "onSuccess: "); | |
} | |
}, new Realm.Transaction.OnError() { | |
@Override | |
public void onError(Throwable error) { | |
error.printStackTrace(); | |
} | |
}); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*realm Object */ | |
package jiran.com.myapplication; | |
import io.realm.RealmObject; | |
import io.realm.annotations.PrimaryKey; | |
/** | |
* Created by user on 2016-07-19. | |
*/ | |
public class realm_test extends RealmObject { | |
@PrimaryKey | |
private String id; | |
private String login_id; | |
public String getLogin_id() { | |
return login_id; | |
} | |
public void setLogin_id(String login_id) { | |
this.login_id = login_id; | |
} | |
public String getId() { | |
return id; | |
} | |
public void setId(String id) { | |
this.id = id; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Application*/ | |
package jiran.com.myapplication; | |
import android.app.Application; | |
import io.realm.Realm; | |
import io.realm.RealmConfiguration; | |
public class MyApplication extends Application { | |
private static MyApplication sInstance; | |
public MyApplication() { | |
sInstance = this; | |
} | |
public static synchronized MyApplication getInstance() { | |
return sInstance; | |
} | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
RealmConfiguration config = new RealmConfiguration.Builder(this) | |
.deleteRealmIfMigrationNeeded() | |
.schemaVersion(0) | |
.build(); | |
Realm.setDefaultConfiguration(config); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment