小编Aan*_*hta的帖子

房间数据库 onConflict = OnConflictStrategy.REPLACE 不起作用

我正在使用 Room 数据库并尝试插入项目列表(例如,在我的案例中包含作者姓名和引用的引用列表)。

以下是我正在使用的代码:

// view model
BaseApp.daoInstance?.appDao()?.insertQuotes(response!!)

// dao
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertQuotes(listData: MutableList<Quote>)
Run Code Online (Sandbox Code Playgroud)

当我再次尝试插入相同的数据时,它总是作为新数据插入而不是替换为当前项目。

我为此OnConflictStrategy.REPLACE研究了很多,但找不到任何正确的答案。

有没有人面临同样的问题并找到解决方案,或者我做错了什么?

先感谢您...!!!

android kotlin android-room

16
推荐指数
1
解决办法
1万
查看次数

ArrayList&lt;String&gt;() 与 arrayListOf&lt;String&gt;()

我正在学习一些 Kotlin 基础知识,并发现了两种语法。

ArrayList<String>()
Run Code Online (Sandbox Code Playgroud)

arrayListOf<String>()
Run Code Online (Sandbox Code Playgroud)

这两者之间有什么区别,因为两者都是 的一部分Kotlin.Collections

collections kotlin

6
推荐指数
1
解决办法
1388
查看次数

蓝牙低功耗 (BLE) 设备与华为手机的连接问题

我们有一款应用程序使用蓝牙低功耗 (BLE) 技术与活动跟踪器等硬件设备进行通信。

所有支持 BLE 的手机均可进行通信,但当我们尝试将追踪器与华为手机连接时,它根本无法工作。

流程如下:

  • 应用程序搜索活动追踪器
  • 当应用程序找到跟踪器时,它会调用蓝牙 Gatt 服务的 connect 方法。
  • 跟踪器应该成功连接,并且应该在“OnConnectionStateChanged()”方法中给出状态 0 和状态 2(成功)的响应。但问题是,它与跟踪器连接不成功。当应用程序发起连接调用时,它立即给出状态为 133(蓝牙 Gatt 失败)的断开回调。

以下是显示问题的日志:

I/Bluetooth: BtGatt.GattService:onConnected() - clientIf=6, connId=0, address=E6:4F:92:69:B7:95
I/Bluetooth: BluetoothProfileService:isAvailable(), mStartError=false, mCleaningUp=false
BluetoothGatt Check Status and NewState: 133|0
I/Bluetooth: BtGatt.GattService:clientDisconnect() - address=E6:4F:92:69:B7:95, connId=null
Run Code Online (Sandbox Code Playgroud)

我们还使用“nRF Connect”应用程序进行了测试,在该应用程序中,它也提供了状态为 133(蓝牙 Gatt 故障)的断开回调。请查找随附的屏幕截图。

在此输入图像描述

如果有人遇到同样的情况,可以帮助我们吗?

android bluetooth bluetooth-lowenergy android-bluetooth huawei-mobile-services

5
推荐指数
1
解决办法
7917
查看次数

Android:获取芯片图标点击事件

我使用材料组件芯片。在芯片中,我们可以获得关闭图标点击和整个芯片点击事件。但无法找到芯片图标点击。

<com.google.android.material.chip.Chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textColor="@color/chip_text_color"
app:checkedIconEnabled="false"
app:chipBackgroundColor="@color/chip_background"
app:chipIcon="@drawable/ic_pencil_edit_button"
app:chipIconSize="15dp"
app:chipIconTint="@color/chip_text_color"
app:chipStrokeColor="@color/colorPrimary"
app:chipStrokeWidth="1dp"
app:closeIconTint="@color/colorYellow"
app:iconStartPadding="@dimen/spacing_tiny" />
Run Code Online (Sandbox Code Playgroud)

芯片图片

android android-chips material-components-android

5
推荐指数
1
解决办法
3384
查看次数