googlecodelabs / android-persistence Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://codelabs.developers.google.com/codelabs/android-persistence
License: Apache License 2.0
Home Page: https://codelabs.developers.google.com/codelabs/android-persistence
License: Apache License 2.0
After going through step 3 point 5, I observed that if you copy and paste the code provided from the tutorial here the code does not compile as there is an extra parameter in showBooksInUi(books, **mBooksTextView**);
The method showBooksInUi expects a List not a List and TextView
https://codelabs.developers.google.com/codelabs/android-persistence/#6
@DAO
should be @Dao
To ensure that the project builds and runs on Android Oreo, the version numbers in the build.gradle
need to be updated.
The LifecycleActivity
extensions need to be replaced with AppCompatActivity
in version 1.0.0
of LifeCycle Extensions.
There are changes to Room 1.0.0
that require Primary Keys to have the annotation @NonNull
.
As well as this, Issue #2 needs to be fixed too, before the project will build.
Today ( Feb 19th 2018), I downloaded the code. I was not able to install straight away. The error being
'Error Running app: Default Activity not found'.
Solution : add inside tag in the manifest.xml ( you can add to any activity, I think to begin with step1.UsersActivity would be right place particularly if you are following the Room CodeLab)
(Just thought some one might find this useful)
On the Persistence Codelab tutorial on 5. Step 3 - Observer Live Data From a ViewModel, on the following step:
5. Next, complete the subscribeUiBooks method by subscribing the activity to changes in the ViewModel object's list of books,:
private void subscribeUiBooks() {
mViewModel.books.observe(this, new Observer<List<Book>>() {
@Override
public void onChanged(@NonNull final List<Book> books) {
showBooksInUi(books, mBooksTextView);
}
});
}
the function call for showBooksInUi()
should only take the list books
, and the mBooksTextView
should not be part of the call. That is in accordance with the definition of showBooksInUi()
in the in the file com.example.android.persistence.codelab/step3/BooksBorrowedByUserActivity.java. The function definition is as follows:
private void showBooksInUi(final @NonNull List<Book> books) {
StringBuilder sb = new StringBuilder();
for (Book book : books) {
sb.append(book.title);
sb.append("\n");
}
mBooksTextView.setText(sb.toString());
}
Thank you.
Can I support auto increment fields? I don't find an annotation that supports this property in your library.
thaks for your reply.
Lines 36, 37 of BookDao.java have a disagreement in the query vs the method signature.
Something like
@Query("select * from Book where id = :id")
Book loadBookById(int id);
@Query("select * from Book where id = :id")
User loadUserById(int id);
This codelab contained basics regarding local data persistence, but didn't add either references to remote data fetching, nor the questionable Repository class.
Deprecating it is a mistake. For example, the Room with a View
sample doesn't even contain INNER JOIN
(more complex queries).
There is a comment to find PersistenceBasicSample that shows how we perform background tasks
Please provide the link ๐
Hi. I think it's wrong to use set method instead of add to add days in the following method:
private static Date getTodayPlusDays(int daysAgo) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE, daysAgo);
return calendar.getTime();
}
Same mistake in code labs.
Addition line should look like this
calendar.add(Calendar.DATE, daysAgo);
P.S. Thanks for examples.
showBooksInUi(books, mBooksTextView);
should be
showBooksInUi(books);
as mBooksTextView is a class var and it is initialised before subscribeUiBooks() is called onCreate()
At https://codelabs.developers.google.com/codelabs/android-persistence/#3 there is this paragraph "Next, open the step1 package and review the UsersActivity class, which fetches data from the database using the following code:" and in code box there is " List youngUsers = mDb.userModel().loadAllUsers();"
But in UsersActivity (Step 1) code there is already List youngUsers = mDb.userModel().findYoungerThan(35);
Step 1 page at Codelab should be the correct, initially.
This one is not about persistence exactly - I've seen this on other codelabs also. More like a "feature" for everywhere on site.
Whenever you move mouse it animates and shows this popup, which has no sense in appearing at all, but does a ton of distraction (maybe it's just me, maybe I have ADHD or whatever - this is killing me).
Pretty please - pass this to someone responsible for supporting the whole codelabs platform. Thanks!
If the method findBooksBorrowedByNameSync return type is changed to LiveData<List < Book > >, then during compilation an error will occur at JankShowUserActivity.java's fetchData method. Changing all instances of parameters with List < Book > type in JankShowUserActivity with result in the foreach method giving a compile time error saying
error: for-each not applicable to expression type for (Book book : books) { ^ required: array or java.lang.Iterable found: LiveData<List<Book>>
Using the latest version of Android Studio, Kotlin and Room. Database_impl does not exist when creating an instance of the database
gradle dependencies
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
}
Database class
@database(entities = arrayOf(Task::class), version = 1, exportSchema = false)
abstract class AppDatabase: RoomDatabase(){
companion object : SingletonHolder<AppDatabase, Context> ({
Room.databaseBuilder(it.applicationContext,
AppDatabase::class.java, "Tasks.db")
.build()
})
abstract var taskDao : TaskDao
}
https://codelabs.developers.google.com/codelabs/android-persistence/#5
The class "BooksBorrowedByUserViewModel" describe in the documentation should inherited from AndroidViewModel and not from ViewModel.
There is nothing to do in it
I modified this code to populate dummy data only for the first time (when app is opened in step 3 solution). I used sharedpreference for that. But now opening for second time, no data is being displayed. Please help me in this.
I used following snippet -
String PREFERENCE_PATH = "com";
SharedPreferences prefs = getApplication().getSharedPreferences(PREFERENCE_PATH, MODE_PRIVATE);
// changed here in BooksBorrowedByUserViewModel class
public void createDb() {
mDb = AppDatabase.getInMemoryDatabase(this.getApplication());
if (isAppLaunchedForFirstTime()) {
prefs.edit().putBoolean(IS_APP_LAUNCHED_FOR_FIRST_TIME, false).apply();
// Populate it with initial data
DatabaseInitializer.populateAsync(mDb);
}
}
private Boolean isAppLaunchedForFirstTime() {
return prefs.getBoolean(IS_APP_LAUNCHED_FOR_FIRST_TIME, true);
}
The code snippet for fetchData()
contains the call mDb.userModel().loadAllUsers()
instead of mDb.userModel().findUsersYoungerThan(35)
as in the provided project.
That makes the sentence about an "impostor" in the sentence that follows confusing because you'd expect to have all ages there.
Downloaded the source and compiled/updated. the "Step 1" configuration is not available to run. The only config available is "app" which doesn't run.
How can one fix this?
Android Studio Version 3.1.1
The resolution for this is to either update the source code, adding the appropriate Run Configurations, or update the CodeLab Instructions describing how users can properly create the needed Run Configurations.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.