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

Commit 0a660fe0 authored by Josh Gargus's avatar Josh Gargus Committed by Android (Google) Code Review
Browse files

Merge "Fix SocialWidgetConfigureActivity contact-picker double-launch." into jb-dev

parents d14d3793 b7cf3f0f
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,