How to check the scope of Android?

how to check whether or not a specific value exists in my database based on this code below?

realm.where(User.class).equalTo("cardId", cardId).findFirst() 

Thanks in advance.

+8
android realm
source share
2 answers

You can perform a null check.

 User user = realm.where(User.class).equalTo("cardId", cardId).findFirst(); if (user != null) { // Exists } else { // Not exist } 
+21
source share

I have the same problem. I have to set the master password for the first time in my application right after installation, and after the guardian just checks it. To do this, I must check the area database if such an object exists, if so, just confirm that the master pass password is still set. Since realm is a nosql database, so we need to check if an object exists instead of a table. Thus,

 CustomObject custom = realm.where(CustomObject.class).findfirst(); if(custom == null){ //set master password } else { //verify master password } 

works for me.

0
source share

All Articles