Status Update
Comments
do...@google.com <do...@google.com> #2
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@google.com> #3
ap...@google.com <ap...@google.com> #4
private void refreshAllLiveData() {
AppDataBase YOUR_DATABASE_WHICH_YOU_BUILD = .....
SupportSQLiteDatabase writableDatabase = YOUR_DATABASE_WHICH_YOU_BUILD.getOpenHelper().getWritableDatabase();
//get the database count;
Cursor cursor = writableDatabase.query("SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name != 'android_metadata' AND name != 'room_master_table';");
int tableCount = 0;
while(cursor.moveToNext()) {
tableCount = cursor.getInt(0);
}
for (int i = 0; i < tableCount; i++) {
//update version table with the incremented count because room modification log stores tables with ids instead of names
writableDatabase.execSQL("INSERT OR REPLACE INTO room_table_modification_log VALUES(null, "+(i)+")");
}
YOUR_DATABASE_WHICH_YOU_BUILD.getInvalidationTracker().refreshVersionsAsync();
}
-----
This is a workaroud for refreshing all live datas, I still prefer to use a proper API you implemented.
Thanx
ap...@google.com <ap...@google.com> #5
cl...@google.com <cl...@google.com> #6
Fixed internally and available in navigation-2.8.0-rc01
.
Note that Android Bundle is deeply integrated into the parsing of arguments by NavType and cannot be removed, hence non-instrumented tests will require robolectric in order to properly support bundles.
ap...@google.com <ap...@google.com> #7
Branch: androidx-main
commit df6f97f72af9fa61365b44af75905ddd9039bb26
Author: Clara Fok <clarafok@google.com>
Date: Tue Jun 18 10:47:42 2024
Update SavedStateHandleFactory kdoc
Clarify that android Bundles cannot be avoided at this stage and non-instrumented tests need to be run with robolectric.
Test: TH
Bug: 340966212
Relnote: "To use SavedStateHandle test factory in non-instrumented tests, robolectric is required. This is because android Bundle is necessarily integrated into the parsing of nav arguments."
Change-Id: I8047c1a2d2dff4cb2efd0452407287738f2ce157
M navigation/navigation-testing/src/main/java/androidx/navigation/testing/SavedStateHandleFactory.kt
do...@google.com <do...@google.com> #8
Thanks for doing this. Whilst this is technically an improvement, the fact remains that if you want to test a ViewModel which accepts navigation arguments you now need to introduce a dependency on Robolectric which is a fairly major blocker for many developers. Robolectric slows down tests and reduces test fidelity.
Is there no way of removing the Bundle
dependency? Or perhaps moving Bundle
into AndroidX?
pr...@google.com <pr...@google.com> #9
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-common:2.8.0-beta04
androidx.navigation:navigation-testing:2.8.0-beta04
do...@google.com <do...@google.com> #10
I created a follow up bug to track the Android dependency forcing unit->instrumented tests for ViewModels.
Description
Component used: Navigation Version used: 2.8.0-beta01 Devices/Android versions reproduced on: all
aosp/3073537 introduced a new API for creating a
SavedStateHandle
using an object for the route parameter e.g.SavedStateHandle(route = MyDestination)
.Internally, this constructor relies on
android.net.Uri
which means that you can only call it from an instrumented test, not a unit test.This is undesirable since one of the use cases for this API is to be able to unit test ViewModels by passing them a
SavedStateHandle
containing a route.Example:https://github.com/android/nowinandroid/pull/1413/files#diff-bbcd9ff3a5be72096922a84b290125441e34d8183492cd27536e343a903579a8R57