I'm working on a project trying for the first time Kotlin, RxJava 2, and the new android architecture components. I'm trying to execute a delete method from Room on separate Thread and I'm getting ERROR: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 12673 (RxCachedThreadS)
when executing the method, and the force closes. I'm trying these two options:
1.
Single.fromCallable { deviceViewModel.delete(device.phone) }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe()
2.
Observable.just(Unit)
.subscribeOn(Schedulers.io())
.map { deviceViewModel.delete(device.phone) }
.subscribe()
Here's my DeviceViewModel.kt (using AndroidViewModel)
class DeviceViewModel constructor(application: Application) : AndroidViewModel(application) {
@Inject lateinit var db: AppDatabase
init {
(application as KaiApplication).appComponent.inject(this)
}
fun count() = db.deviceModel().count();
fun getDevices() = db.deviceModel().devices();
fun getDevice(phone: String) = db.deviceModel().device(phone)
fun create(device: Device): Device {
db.deviceModel().createOrUpdate(device).let {
return device
}
}
fun createTestDevice(name: String, phone: String) {
db.deviceModel().createTestDevice(name, phone)
}
fun delete(device: Device): Device {
db.deviceModel().delete(device).let {
return device
}
}
fun delete(devicePhone: String) {
db.deviceModel().delete(devicePhone)
}
And my DeviceDao.kt
@Dao
abstract class DeviceDao {
@Query("SELECT COUNT(*) FROM device")
abstract fun count(): Int
@Query("SELECT * FROM device")
abstract fun devices(): Flowable<List<Device>>
@Query("SELECT * FROM device WHERE phone = :p0")
abstract fun device(phone: String): Device?
fun createOrUpdate(device: Device) {
Timber.d("Device to create $device")
insertOrUpdate(device)
}
fun createTestDevice(name: String, phone: String) {
val device: Device = Device()
device.phone = phone
device.name = name
device.password = "12345"
Timber.d("Device to create $device")
insertOrUpdate(device)
}
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insertOrUpdate(vararg devices: Device)
@Query("DELETE FROM device WHERE phone = :p0")
abstract fun delete(phone: String)
@Delete
abstract fun delete(device: Device)
I've tried to solve this, but no success. Any help would come in hand. Thanks!