Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7cf3f0f authored by Josh Gargus's avatar Josh Gargus
Browse files

Fix SocialWidgetConfigureActivity contact-picker double-launch.

No longer does SocialWidgetConfigureActivity launch a second
contact-picker when the picker result is returns in a different
device orientation.

Bug: 6478425
Change-Id: I51c6e91afb269f07bf45fb29aa017a0044baa237
parent 888ed02d
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -23,18 +23,33 @@ import android.os.Bundle;
import android.provider.ContactsContract.Contacts;

public class SocialWidgetConfigureActivity extends Activity {
    private static final String KEY_LAUNCHED = "already_launched_picker_activity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // If the user presses back, we want to cancel
        setResult(RESULT_CANCELED);

        // Don't launch contact-picker if we already launched it (for example, if
        // we launched it in a previous onCreate() and the device orientation changes
        // before the picker returns its result, then this activity will be recreated).
        if (savedInstanceState != null && savedInstanceState.getBoolean(KEY_LAUNCHED)) return;

        // Forward the Intent to the picker
        final Intent pickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
        pickerIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivityForResult(pickerIntent, 0);
    }

    @Override
    protected void onSaveInstanceState(Bundle savedInstanceState) {
        super.onSaveInstanceState(savedInstanceState);

        // We know for sure that we've launched the contact-picker... see onCreate()
        savedInstanceState.putBoolean(KEY_LAUNCHED, true);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // We came back from the Picker. If the user actually selected a contact,