Reputation: 2465
I have a database in my app. Here's the way how I create it:
App
class:
public class TraktTvApp extends Application {
private static Context sAppContext;
public static TraktTvApp instance;
private MovieDatabase database;
@Override
public void onCreate() {
super.onCreate();
sAppContext = getApplicationContext();
instance = this;
database = Room.databaseBuilder(this, MovieDatabase.class, "MovieDatabase").build();
}
@NonNull
public static Context getAppContext() {
return sAppContext;
}
public static TraktTvApp getInstance() {
return instance;
}
public MovieDatabase getDatabase() {
return database;
}
}
DAO
class
@Dao
public interface MovieDao {
@Query("SELECT * from MovieEntity")
List<MovieEntity> getFavorites();
@Insert(onConflict = OnConflictStrategy.REPLACE)
Completable insertMovie(final MovieEntity movie);
@Delete
void deleteMovie(MovieEntity movie);
}
Database
class
@Database(entities = {MovieEntity.class}, version = 1)
public abstract class MovieDatabase extends RoomDatabase {
public abstract MovieDao movieDao();
}
And here's the way how I call insert
method:
mCompositeDisposable.add(Observable.fromCallable(()->movieDao.insertMovie(movieEntity))
.doOnSubscribe(disposable -> mView.showLoadingIndicator(true))
.doOnComplete(() -> {
mView.showEmptyState(false);
mView.onMoviesAdded();
})
.doOnError(throwable -> mView.showEmptyState(true))
.doOnTerminate(() -> mView.showLoadingIndicator(false))
.observeOn(Schedulers.io())
.subscribe());
But when I want to check data in my database in Stetho, there's nothing here:
So, what's the matter and how can I solve this problem? It seems to me that it can be problem in creating database, but I used the same way as usual and usually it works ok
Upvotes: 0
Views: 170
Reputation: 301
call setupDebugTools()
in application's onCreate()
like
{
super.onCreate()
setupDebugTools()
}
And
private void setupDebugTools() {
if (BuildConfig.DEBUG) {
Stetho.initializeWithDefaults(this)
}
}
for more information
Upvotes: 0