Fix crash after tapping "Configure widget" in Settings (#1242)
* Fix crash after tapping "Configure widget" in Settings > Home screen > Clock Closes #1221 * Fix another crash --------- Co-authored-by: MM20 <15646950+MM2-0@users.noreply.github.com>
This commit is contained in:
parent
3f187af1d2
commit
a371213d4a
@ -478,9 +478,6 @@ fun ColumnScope.ConfigureAppWidget(
|
||||
.setPendingIntentBackgroundActivityStartMode(
|
||||
ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
|
||||
)
|
||||
.setPendingIntentCreatorBackgroundActivityStartMode(
|
||||
ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
|
||||
)
|
||||
.toBundle()
|
||||
}
|
||||
)
|
||||
|
||||
@ -4,6 +4,7 @@ import android.app.Activity
|
||||
import android.app.ActivityOptions
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.os.Build
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.animateContentSize
|
||||
@ -210,7 +211,7 @@ fun WatchFaceSelector(
|
||||
},
|
||||
onClick = {
|
||||
appWidgetHost.startAppWidgetConfigureActivityForResult(
|
||||
context as Activity,
|
||||
getActivityFromContext(context) ?: return@DropdownMenuItem,
|
||||
selected.widgetId ?: return@DropdownMenuItem,
|
||||
0,
|
||||
0,
|
||||
@ -221,9 +222,6 @@ fun WatchFaceSelector(
|
||||
.setPendingIntentBackgroundActivityStartMode(
|
||||
ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
|
||||
)
|
||||
.setPendingIntentCreatorBackgroundActivityStartMode(
|
||||
ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
|
||||
)
|
||||
.toBundle()
|
||||
}
|
||||
)
|
||||
@ -589,3 +587,17 @@ private fun ResizeCustomWidget(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getActivityFromContext(context: Context): Activity? {
|
||||
var activity = context
|
||||
|
||||
while (activity is ContextWrapper) {
|
||||
if (activity is Activity) {
|
||||
return activity
|
||||
}
|
||||
|
||||
activity = activity.baseContext
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user