Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Realm - debugging [duplicate]

I want to see the values of Realm object variables

For Example:

Student (int studentID, ArrayList <Subject> subjectList)

Subject (int subjectID, String subjectName)

I want to see the names of subjects in a student object when debugging using Android Studio.

Where should I look in android studio debug window to find a student's the subjects list?

like image 291
ChaturaM Avatar asked Jul 15 '15 03:07

ChaturaM


3 Answers

Realm proxies your model objects and is a zero-copy storage system so in order to inspect the value of a field you need to use the evaluate expression feature of the debugger.

We are considering the possibility to write a plugin for the debugger to show the values directly, but that is still at an investigation stage.

like image 148
Emanuelez Avatar answered Oct 09 '22 21:10

Emanuelez


You cannot directly do like that.

this my approach.

 List<FooObject> messages = realm.copyFromRealm(value);

And you can see in debugger values from messages.

Full Code

realm.where(FooObject.class).equalTo(FooObject.id, id).findAllAsync().asObservable()
            .filter(new Func1<RealmResults<FooObject>, Boolean>() {
                @Override
                public Boolean call(RealmResults<FooObject> message) {
                    return message.isLoaded();
                }
            }).subscribe(new SimpleObserver<RealmResults<FooObject>>() {
                @Override
                public void onCompleted() {
                    super.onCompleted();
                }

                @Override
                public void onNext(RealmResults<FooObject> value) {
                    super.onNext(value);
                    List<FooObject> messages = realm.copyFromRealm(value);
                    RLog.d(TAG, "Messages");
                }

                @Override
                public void onError(Throwable e) {
                    super.onError(e);
                }

                @Override
                public String getTag() {
                    return TAG;
                }
            });
like image 33
raditya gumay Avatar answered Oct 09 '22 22:10

raditya gumay


You can use Stheto from FaceBook. You will be able to see dynamic changes and all table etc. here is the link : https://github.com/uPhyca/stetho-realm

I will explain here: import the lib from gradle with

>  compile 'com.facebook.stetho:stetho:1.5.0'
>  compile 'com.uphyca:stetho_realm:2.1.0'

then in a class extends Application (dont forget to notify the manifest about your class :

 <application
        android:allowBackup="true"
        tools:ignore="AllowBackup"
        android:name=".YourClassName"

then add this

public class YourClassName extends Application {
...
 @Override
    public void onCreate() {
     Stetho.initialize(
                    Stetho.newInitializerBuilder(this)
                            .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                            .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
                            .build());

finnaly open chrome on this url

chrome://inspect/#devices 

And click on inspect. Go on Ressources then on Web Sql. You will be able to see your db like that enter image description here

like image 25
Dagnogo Jean-François Avatar answered Oct 09 '22 21:10

Dagnogo Jean-François