当我收到一些通知时,我正在尝试创建一个透明的对话框活动。对话框活动有一个ok按钮,如果我单击它,它将返回带有标志的主活动:Intent.FLAG_ACTIVITY_CLEAR_TOP和Intent.FLAG_ACTIVITY_SINGLE_TOP
问题 当我回到主屏幕时,屏幕变黑约一秒钟,我想知道如何解决它。谢谢你的帮助。
我的对话活动的主题:
<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:
@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);
}
答案 0 :(得分:0)
您可以使用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();
}
}