How get value from executeTransaction (inner class)?
See original GitHub issueMy code that insert/update incoming profile to Realm:
public Profile saveProfile(final String incomingProfileJson) throws Exception {
Realm realm = Realm.getDefaultInstance();
try {
final Profile incomingProfile = JsonUtil.gson.fromJson(incomingProfileJson, Profile.class);
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Profile findProfile = realm.where(Profile.class).equalTo(Profile.ID, 123).findFirst();
if (findProfile != null) {
if (incomingProfile.getName() != null) {
findProfile.setName(incomingProfile.getName());
}
if (incomingProfile.getDiscount() != null) {
findProfile.setDiscount(realm.copyToRealm(incomingProfile.getDiscount()));
}
} else { // new oraanization
realm.copyToRealmOrUpdate(incomingProfile);
}
}// execute
});
// need return after success updated in Realm
return <<<<how_get_actual_upated_profile>>>>;
} finally {
realm.close();
}
}
In my code I insert new profile or update exist profile. OK. It’s work fine. But as you can see I must return profile (how_get_actual_upated_profile) that was success inserted/updated to Realm. So I need some method that call IMMEDIATELY AFTER success update profile to Realm. How I can do this. Maybe has some listener?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Get value of variable from inner class - java - Stack Overflow
First, your method public ArrayList<Message> getLastTenMessageCallBack(...) has synchronous signature, but implementation is asynchronous.
Read more >Realm (Realm 4.1.1) - MongoDB
The Realm class is the storage and transactional manager of your object persistent store. ... Objects within a Realm can be queried and...
Read more >io.realm.Realm.executeTransaction java code examples
@Override public void onComplete(Result<List<TradeTag>> result,Realm realmDefault) { if (!resultHandler(result)){ return; } initList(result.
Read more >Java - Inner classes - Tutorialspoint
Java - Inner classes, This Java tutorial covers basic to advanced concepts ... to access the private members) call the getValue() method of...
Read more >Nested Classes - Learning the Java Language
The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Well it’ll do.
Here my solution. I user method
copyFromRealm. So as result I don’t worry aboutrealm.close.And now I return correct updated Profile.
Is this a good solution?