Glance App widget in Jetpack compose take delay of widget when app is closed

168 Views Asked by At
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)
            }
        }
    }}

When app is not in background tap on widget app is not open directly. If anyone know give me solution for above problem.

1

There are 1 best solutions below

2
On

You can use the clickable modifier on your parent composable.

     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
            ))
    )