I'm using Realm to provide the database for my application. But...
After login, the server returns the data and I create the account (of AccountManager) and save these datas at the database of the application, like this (at an AsyncTask, of course):
UserRealm userRealm = new UserRealm();
//setter of the userRealm...
Realm realm = Realm.getInstance(context);
realm.beginTransaction();
realm.copyToRealmOrUpdate(userRealm);
realm.commitTransaction();
realm.close();
After, I close the LoginActivity and at the onResume of the MainActivity, I try to load the user, like this(at an AsyncTask, again...):
public static UserRealm getUser(Context context) {
try {
return Realm.getInstance(context).where(UserRealm.class).findFirst();
} catch (Exception e) {
if(DebugUtil.DEBUG) { //enabled
e.printStackTrace();
}
}
return null;
}
But this returns null, I don't know what happens with it.
UserRealm: https://gist.github.com/ppamorim/88f2553a6ff990876bc6