当我单击项目时没有任何反应,我尝试更改颜色、显示所选元素的数量、显示日志什么也没有发生
我的ViewHolder
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val name: TextView = view.list_item_name
val phone: TextView = view.list_item_phone
// More code here
fun getItemDetails(): ItemDetailsLookup.ItemDetails<Long> =
object : ItemDetailsLookup.ItemDetails<Long>() {
override fun getSelectionKey(): Long? = itemId
override fun getPosition(): Int = adapterPosition
}
}
Run Code Online (Sandbox Code Playgroud)
我的物品详情查找
class MuLookup(private val rv: RecyclerView) : ItemDetailsLookup<Long>() {
override fun getItemDetails(event: MotionEvent): ItemDetails<Long>? {
val view = rv.findChildViewUnder(event.x, event.y)
if (view != null) {
return (rv.getChildViewHolder(view) as MyViewHolder)
.getItemDetails()
}
return null
}
}
Run Code Online (Sandbox Code Playgroud)
我的适配器 …
我按照Android 指南在媒体播放器应用程序中使用 MediaBrowserServiceCompat,但该服务在应用程序退出时被销毁。
<service android:name=".media.PlaybackService">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
在应用程序启动时正确创建服务。按下按钮时mediaController.transportControls.play()被调用,并且在onPlay()调用我的会话回调类中的此方法之后。内部onPlay()服务启动:(context.startService(Intent(context, MediaBrowserServiceCompat::class.java))也尝试startForegroundService过 Oreo 及更高版本)并设置为前台:this@PlaybackService.startForeground(SERVICE_ID, notificationBuilder?.build())。创建了 Oreo 和更高 API 的通知通道。
现在通知已启动,我可以通过发出命令看到服务位于前台:
Run Code Online (Sandbox Code Playgroud)$adb shell dumpsys activity services PlaybackService (...) isForeground=true foregroundId=1 foregroundNoti=Notification(channel=MyChannelId pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x62 color=0xff000000 category=transport actions=1 vis=PUBLIC) (...)
到目前为止,一切正常,但当我按下主页按钮时,我希望服务保持启动状态,但会调用onDestroy()我的类的方法。MediaBrowserServiceCompat返回应用程序并再次启动服务后,它不会设置为前台(也没有通知)。
我startService在我的应用程序中使用了唯一的一个调用,并删除了每个调用stopSelf和stopForeground测试。
在 API 28、26、22 和 18 上我得到了相同的结果。
我也尝试START_STICKY过从onStartCommand().