Jetpack 中的 Glance 应用程序小部件在应用程序关闭时会延迟小部件

问题描述 投票:0回答:1
class ClickActionCallback : ActionCallback {
    override suspend fun onAction(
        context: Context,
        glanceId: GlanceId,
        parameters: ActionParameters,
    ) {
        with(parameters) {
            val serverId = this[FactWidget.factPosition]
            withContext(Dispatchers.Main) {
                val actionIntent = Intent(context, FactActivity::class.java)
                actionIntent.putExtra(Constants.SERVER_ID, serverId)
                actionIntent.putExtra(Constants.STORED_TIME, System.currentTimeMillis())
                actionIntent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT or
                            Intent.FLAG_ACTIVITY_CLEAR_TOP or
                            Intent.FLAG_ACTIVITY_NEW_TASK or
                            Intent.FLAG_ACTIVITY_CLEAR_TASK
                context.startActivity(actionIntent)
            }
        }
    }}

当应用程序不在后台时,点击小部件应用程序不会直接打开。 如果有人知道请给我解决上述问题。

android widget android-jetpack-compose glance
1个回答
0
投票

您可以在父可组合项上使用可点击修饰符。

     val intent = Intent(LocalContext.current,HomeActivity::class.java).apply {
        setAction("fdo")
        putExtra(Constants.WIDGET,"widget")
     }


    Box(
        modifier = GlanceModifier
            .cornerRadius(20.dp)
            .background(Color.LightGray)
            .clickable(
                androidx.glance.appwidget.action.actionStartActivity(
                intent
            ))
    ) 
© www.soinside.com 2019 - 2024. All rights reserved.