سؤال

I have this issue I start an Activity as a Dialog with attribute android:theme="@android:style/Theme.Dialog" so far so good, when I run this Activity I want the user to fill some EditTexts and then press a button where a background process will be started, now I use this.setFinishOnTouchOutside(false); to pervent the user from clicking outside and finish() being called, my problem is that I don't get how to finish() specifically this DialogLikeActivity, when i call finish() after the background process is started the application is close and i want to return to the MainActivity or the Activity that started the DialogLikeActivity (the MainActivity still visible after the startActivity or startActivityForResult() is called for the DialogLikeActivity, here is what i got:

Code From MainActivity:

Intent intent = new Intent(this, DialogLikeActivity.class);
        startActivityForResult(intent,0);

and the button code in DialogLikeActivity:

public void saveClient(View view){
    Intent returnIntent = new Intent();
    setResult(RESULT_OK, returnIntent);
    finish();


}

I guess maybe my problem is that MainActivity is not a parent of DialogLikeActivity, in that case it should be? how to make DialogLikeActivity child of MainActivity and if I achieve that would the call for finish() in DialogLikeActivity finish the Activity itself and not the app?

Thanks in advance and sorry for my english.

EDIT:

this is the Activity being displayed as a Dialog above the MainActivity

هل كانت مفيدة؟

المحلول

It sounds like DialogFragment might better suit your needs here. It has lifecycle methods similar to an Activity and can run background tasks within itself, but is actually managed by the activity it is attached to. There are several types you can use.

Check out the Google documentation on it HERE.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top