views:

62

answers:

1

Hello,

I have a Service and a PreferenceActivity that allows the user to edit some preferences. I would like to restart the Service once the user is done with the PreferenceActivity.

I understand that I can register onChange listeners for individual preference changes, but I do not want to restart the Service as each preference changes. I would like to do this when the user is done editing all the preferences. Short of having a "Apply Now" button in the PreferenceActivity, I do not see a straightforward way of doing this.

Am I missing something fundamental here?

Thanks!

A: 

In the Activity that starts the PreferenceActivity use startActivityForResult and onActivityResult to track when the user has finished the PreferenceActivity and restart the service there.

eg.

Wherever you're starting the PreferenceActivity:

Intent prefIntent = new Intent(this, MyPreferenceActivity.class);
startActivityForResult(prefIntent, PREFS_UPDATED);

later in that same Activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (resultCode) {
        case PREFS_UPDATED:
            // restart service
            break;
        ...
    }
}
codelark