Open an Activity twice but with different values

Asked

Viewed 59 times

0

Androidmanifest:

<activity android:name=".pictureManagement.boundary.DocsIDUI"
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:screenOrientation="portrait"
        android:launchMode="singleTask">

    </activity>

    <activity android:name=".pictureManagement.boundary.PicturePreview"
        android:screenOrientation="portrait"
        android:launchMode="singleTask">

    </activity>

Activity Docsidui:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        if (photoFile != null) {
            imageUri = Uri.fromFile(photoFile);

            Intent intent = new Intent(DocsIDUI.this, PicturePreview.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable(PicturePreview.NAME, name);
            if (!isBackStep)
            {
                bundle.putSerializable(PicturePreview.STEP, 0);
            } else
            {
                bundle.putSerializable(PicturePreview.STEP, 1);
            }
            bundle.putSerializable(PicturePreview.URI_PHOTO, imageUri.toString());
            intent.putExtras(bundle);
            DocsIDUI.this.startActivity(intent);

        }
    }
}

Activity Picturepreview:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_picture_preview);

    getNewIntent(getIntent());

    getImage();

    getComponents();

    setListeners();
}

@Override
protected void onResume(){
    super.onResume();

    getNewIntent(getIntent());
}
private void getNewIntent(Intent intent) {
    if (intent != null && intent.hasExtra(URI_PHOTO)) {
        this.stringUri = (String) intent.getSerializableExtra(URI_PHOTO);
        imageUri = Uri.parse(stringUri);
    }
    if (intent != null && intent.hasExtra(NAME)) {
        this.name = (String) intent.getSerializableExtra(NAME);
    }
    if (intent != null && intent.hasExtra(STEP)) {
        this.step = (int) intent.getSerializableExtra(STEP);
    }
}

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
}

When you first open Activity Picturepreview (Docsidui -> Picturepreview), it normally opens, but when you return and open Picturepreview a second time, when isBackStack is positive, it does not open by going straight through

1 answer

0

The way I found it was to change inside the manifest the "launchMode"

android:launchMode="singleInstance"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.