How can I use Stetho with RoomDataBase in Android Studio?

274 views Asked by At

I'am using RoomDatabase in my android studio project. And I want to inspect my database with Stetho. I already add it in my build.gradle file, but I don't know where to write the code Stetho.initializeWithDefaults(this);, to begin inspection. Thanks

2

There are 2 answers

0
Kévin Giacomino On BEST ANSWER

You can write the code inside your main app file.

Also you can put it in any activity but if you want to get stetho globally i recommand to put it inside your app file.

0
Basi On

Integrating with Stetho is intended to be seamless and straightforward for most existing Android applications. There is a simple initialization step which occurs in your Application class:

public class MyApplication extends Application {
  public void onCreate() {
    super.onCreate();
    Stetho.initializeWithDefaults(this);
  }
}

Also ensure that your MyApplication Java class is registered in your AndroidManifest.xml file, otherwise you will not see an "Inspect" button in chrome://inspect/#devices :

<manifest
        xmlns:android="http://schemas.android.com/apk/res/android"
        ...>
        <application
                android:name="MyApplication"
                ...>
         </application>
</manifest>

This brings up most of the default configuration but does not enable some additional hooks (most notably, network inspection). See this for specific details on individual subsystems.