Android Realm - debugging [duplicate]

陌路散爱 提交于 2019-12-12 11:02:44

问题


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?


回答1:


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.




回答2:


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;
                }
            });



回答3:


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



来源:https://stackoverflow.com/questions/31420948/android-realm-debugging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!