I have an app which basically consists of a widget. I need to configure this widget, that is the reason why I use a configuration activity. I thought it would be very simple to use a PreferenceActivity
as the configuration activity.
I already googled up some things but at some point I stuck. All tutorials say, that I need to do this when configuration is finished:
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_OK, resultValue);
finish();
Now, this works fine when simply copied for non-sense in the onCreate()
method of the PreferenceActivity
. Since it is a PreferenceActivity
, I have nothing like a button, which says "Configuration finished" and I even can not add such a button in a PreferenceActivity
. When the above code is added to the onDestroy()
method it seems like it is too late because the widget is not created eventually. But onDestroy()
or onStop()
is the only place where the configuration is finished because the user pressed the Android back button.
What is a reasonable solution for this?
You can override onBackPressed()
:
@Override
public void onBackPressed()
{
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}