@@ -74,6 +74,12 @@ class TodoWidgetConfigureActivity : BaseActivity() {
7474 }
7575 }
7676
77+ private val widgetId: Int
78+ get() = intent.extras?.getInt(
79+ AppWidgetManager .EXTRA_APPWIDGET_ID ,
80+ AppWidgetManager .INVALID_APPWIDGET_ID ,
81+ ) ? : AppWidgetManager .INVALID_APPWIDGET_ID
82+
7783 private val viewModel: TodoWidgetConfigureViewModel by viewModels(
7884 extrasProducer = {
7985 defaultViewModelCreationExtras.withCreationCallback<TodoWidgetConfigureViewModel .Factory > { factory ->
@@ -95,10 +101,6 @@ class TodoWidgetConfigureActivity : BaseActivity() {
95101 // Set the result to CANCELED. This will cause the widget host to cancel
96102 // out of the widget placement if the user presses the back button.
97103 setResult(RESULT_CANCELED )
98- val widgetId = intent.extras?.getInt(
99- AppWidgetManager .EXTRA_APPWIDGET_ID ,
100- AppWidgetManager .INVALID_APPWIDGET_ID ,
101- ) ? : AppWidgetManager .INVALID_APPWIDGET_ID
102104
103105 viewModel.onSetup(widgetId, supportedTextColors)
104106
@@ -141,7 +143,10 @@ class TodoWidgetConfigureActivity : BaseActivity() {
141143 private suspend fun onUpdateWidget () {
142144 try {
143145 viewModel.updateWidgetConfiguration()
144- setResult(RESULT_OK )
146+ setResult(
147+ RESULT_OK ,
148+ Intent ().putExtra(AppWidgetManager .EXTRA_APPWIDGET_ID , widgetId),
149+ )
145150 viewModel.updateWidget(this @TodoWidgetConfigureActivity)
146151 finish()
147152 } catch (_: Exception ) {
0 commit comments