I have followed this tutorial, written directly by google.
The problem, that I currently have, is the line userDao.save(response.body()); inside the UserRepository class.
private void refreshUser(final String userId) {
executor.execute(() -> {
// running in a background thread
// check if user was fetched recently
boolean userExists = userDao.hasUser(FRESH_TIMEOUT);
if (!userExists) {
// refresh the data
Response response = webservice.getUser(userId).execute();
// TODO check for error etc.
// Update the database.The LiveData will automatically refresh so
// we don't need to do anything else here besides updating the database
userDao.save(response.body());
}
});
}
When I try to do that in my Android Studio Version, I get a message which says that Lambda expressions are not supported at this language level.

I am aware of the fact that I can upgrade my Android Studio to support Java 8 like that, BUT- is there an other way to do so? I don't want to upgrade to Java 8 just to use Lambda Expressions.
If you don't want to use Java 8 (which you should reconsider), you can manually replace:
executor.execute(() -> {
// task...
});
with:
executor.execute(new Runnable() {
@Override
public void run() {
// task...
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With