0

I'm trying to create a transparent dialog activity when I receive some notice.The dialog activity has an ok button,and if I click this it will return back to main activity with the flag: Intent.FLAG_ACTIVITY_CLEAR_TOP and Intent.FLAG_ACTIVITY_SINGLE_TOP.

Problem When I go back to main, the screen turns black for about one second, and I want to know how to fix it. Thanks for your help.

the theme of my dialog activity:

<style name="MyDialogStyle">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowFrame">@null</item> 
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:backgroundDimEnabled">true</item>
</style>

OnClickListener of the button of dialog:

@Override
    public void onClick(View v) {
            finish();
            Intent resultIntent = new Intent(DialogActivity.this,
                    MainActivity.class);
            resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP
                    );
            DialogActivity.this.startActivity(resultIntent);
    }
melody
  • 1

1 Answers1

0

You can use startActivityForResult(resultIntent,requestCode);

@Override
public void onClick(View v) {
        finish();
        Intent resultIntent = new Intent(DialogActivity.this,
                MainActivity.class);
        resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP
                );
        DialogActivity.this.startActivity(resultIntent,requestCode);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode==requestCode)
    {
         finish();   
    }
}
Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98