android-database

How can I check if a value e.g. name exists in a collection within any of documents in Cloud Firestore?

妖精的绣舞 提交于 2021-02-17 06:44:05
问题 I want to check if a value e.g. (name: ‘John’) exists in the collection of any document in my Cloud Firestore, because if it does I do not want to create a new document with that name (in this case ‘John’). How can I check if the name exists? 回答1: Assuming you have in Firestore a collection called "users", to check if a user with the name of "John" already exists, please use the following lines of code: FirebaseFirestore rootRef = FirebaseFirestore.getInstance(); CollectionReference usersRef

Room exception on table: Pre-packaged database has an invalid schema

99封情书 提交于 2021-02-11 17:25:28
问题 my task is to migrate the current architecture of our app (using Cupboard) to Room and I am encountering some issues on the very first piece of work, which is migrating the database objects, written in Java for now (Cupboard only supports Java), to make them work with Room. This is an example: public class ItemDb { public Long _id; public String type; public String subtype; public long scheduledTime; public int iteration; public String data1; public String data2; public String data3; and this

Does Android Room offer SqliteOpenHelper onCreate() & onUpdate() alternative?

眉间皱痕 提交于 2021-02-11 14:39:46
问题 Using SqliteOpenHelper, I can rely on the onCreate() method to initialize some database work if the database is created for the first time. Also, using the onUpdate() method, I can easily detect if the user has an older version of the DB and I can update it easily. Does Room support alternative methods to use? 回答1: 1. SQLiteOpenHelper.onCreate YES, there is Callback class for that. You can add Callback to RoomDatabase.Builder like this Room.databaseBuilder(getApplicationContext(), MyDb.class,

Saving png image in database through android app

感情迁移 提交于 2021-02-08 12:10:13
问题 I want to save image using my developed app into mobile what is the best way to it. I was trying to save via sqlite but is there any other options? 回答1: The recommended way is to store the image as a file not in the database and then store the path or enough of the path to uniquely identify the image in the database. To store an image you have to store it as a BLOB based upon a byte[] (byte array); However, using the Android SDK, there is a limitation that only images less than 2MB can be

Saving png image in database through android app

本秂侑毒 提交于 2021-02-08 12:06:48
问题 I want to save image using my developed app into mobile what is the best way to it. I was trying to save via sqlite but is there any other options? 回答1: The recommended way is to store the image as a file not in the database and then store the path or enough of the path to uniquely identify the image in the database. To store an image you have to store it as a BLOB based upon a byte[] (byte array); However, using the Android SDK, there is a limitation that only images less than 2MB can be

Saving png image in database through android app

和自甴很熟 提交于 2021-02-08 12:06:11
问题 I want to save image using my developed app into mobile what is the best way to it. I was trying to save via sqlite but is there any other options? 回答1: The recommended way is to store the image as a file not in the database and then store the path or enough of the path to uniquely identify the image in the database. To store an image you have to store it as a BLOB based upon a byte[] (byte array); However, using the Android SDK, there is a limitation that only images less than 2MB can be

Android Room Database Ignore Problem “Tried the following constructors but they failed to match”

情到浓时终转凉″ 提交于 2020-12-11 05:10:12
问题 My entity class: @Entity(tableName = "student") data class Student( var name: String, var age: Int, var gpa: Double, var isSingle: Boolean, @PrimaryKey(autoGenerate = true) var id: Long = 0, @Ignore //don't create column in database, just for run time use var isSelected: Boolean = false ) And then I insert like this (tested in androidTest ): val student = Student("Sam", 27, 3.5, true) studentDao.insert(student) It gives me this error right after I added the @Ignore annotation: C:\Android

Android Room Database Ignore Problem “Tried the following constructors but they failed to match”

早过忘川 提交于 2020-12-11 05:08:31
问题 My entity class: @Entity(tableName = "student") data class Student( var name: String, var age: Int, var gpa: Double, var isSingle: Boolean, @PrimaryKey(autoGenerate = true) var id: Long = 0, @Ignore //don't create column in database, just for run time use var isSelected: Boolean = false ) And then I insert like this (tested in androidTest ): val student = Student("Sam", 27, 3.5, true) studentDao.insert(student) It gives me this error right after I added the @Ignore annotation: C:\Android

Android Room Database Ignore Problem “Tried the following constructors but they failed to match”

烈酒焚心 提交于 2020-12-11 05:08:00
问题 My entity class: @Entity(tableName = "student") data class Student( var name: String, var age: Int, var gpa: Double, var isSingle: Boolean, @PrimaryKey(autoGenerate = true) var id: Long = 0, @Ignore //don't create column in database, just for run time use var isSelected: Boolean = false ) And then I insert like this (tested in androidTest ): val student = Student("Sam", 27, 3.5, true) studentDao.insert(student) It gives me this error right after I added the @Ignore annotation: C:\Android