Benefit All Lifters 01 : Api desugaring, Room @TypeConverter

Dmitry Klokov·2021년 5월 1일
0

BENEFIT-ALL-LIFTERS

목록 보기
1/2

1. Cannot figure out how to save this field into database.


Problem

@Entity(tableName = "routines")
data class Routine (
	// other fields ...
    	@ColumnInfo(name = "date")
        var date: LocalDate = LocalDate.now()
 )

...Why?

Referencing complex data using Room | Android Developer

Room provides functionality for converting between primitive and boxed types but doesn't allow for object references between entities.

Use type converters

Sometimes, you need your app to store a custom data type in a single database column. You support custom types by providing type converters, which are methods that tell Room how to convert custom types to and from known types that Room can persist. You identify type converters by using the @TypeConverter annotation.

Solution

Test

2. Add @RequiresApi(O) Annotation...?


Problem

...Why?

Use Java 8 language features and APIs | Android developer

If you're building your app using Android Gradle plugin 4.0.0 or higher, the plugin extends support for using a number of Java 8 language APIs without requiring a minimum API level for your app.

This additional support for older platform versions is possible because plugin 4.0.0 and higher extend the desugaring engine to also desugar Java language APIs. So, you can include standard language APIs that were available only in recent Android releases (such as java.util.streams) in apps that support older versions of Android.

Solution

Result

profile
Power Weekend

0개의 댓글