How to check if data is inserted in Room Database

后端 未结 7 2569
执念已碎
执念已碎 2021-02-19 22:07

I am using Room Database from the new Architecture components in my project. I am adding some data through dao, but when trying to retrieve it I am not getting it. Can you pleas

7条回答
  •  野的像风
    2021-02-19 22:25

    You can use Android Debug Database to access your application's databases via a web browser. Android Debug Database exposes the databases via an embedded web server.

    Use it as follows:

    1. Include it as debugImplementation dependency in your app's build.gradle so that it will only be included in debug build and not in release build:

      debugImplementation 'com.amitshekhar.android:debug-db:1.0.3'
      
    2. Start the debug build of your app

    3. The embedded web server launches automatically and announces its address and port in the logs:

      D/DebugDB: Open http://XXX.XXX.X.XXX:8080 in your browser
      
    4. If you are running the app over USB, setup portforwarding:

      adb forward tcp:8080 tcp:8080
      

      If you are not running the app over USB, your Android phone and workstation need to be in the same network and your workstation should be able to ping the Android phone.

    5. Finally, open the link from the logs in the browser.

    Note that it works just fine without rooting the device as the web server runs inside your app context.

提交回复
热议问题