I have a Service (called AlarmService) that opens an Dialog-themed Activity when intent is received (service is called at a specific time).
@Override
protected void onHandleIntent(Intent intent) {
Intent dialogIntent = new Intent(ctx, LogoutConfirmDialog.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);
}
I have LogoutConfirmDialog defined in AndroidManifest.xml:
<activity android:name=".LogoutConfirmDialog"
android:theme="@android:style/Theme.Holo.Dialog" />
Activity LogoutConfirmDialog just creates an AlertDialog and shows it:
public class LogoutConfirmDialog extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setTitle(R.string.dialog_logout_title);
b.setMessage(R.string.dialog_logout_message);
b.setPositiveButton(R.string.dialog_logout_positive, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
AlarmService.logout();
}
});
b.setNegativeButton(R.string.dialog_logout_negative, null);
AlertDialog dialog = b.create();
dialog.show();
}
}
Now the problem is that when the LogoutConfirmDialog is shown, it shows two dialogs on top of each other.
- First one is my dialog that has the title, message, positive and negative buttons set in onCreate of LogoutConfirmDialog.
- Second one having nothing but a title (some kind of default Dialog),
From the logs I can see that it LogoutConfirmDialog is started only once but window manager adds two windows.
ActivityManager﹕ START u0 {flg=0x10000000 cmp=com.mypackage/.LogoutConfirmDialog} from uid 10104 on display 0
WindowManager﹕ Adding window Window{d342658 u0 com.mypackage/com.mypackage.LogoutConfirmDialog} at 6 of 13 (after Window{7e66f7b u0 com.mypackage/com.mypackage.MainActivity})
V/WindowManager﹕ Adding window Window{1100c096 u0 com.mypackage/com.mypackage.LogoutConfirmDialog} at 6 of 14 (before Window{d342658 u0 com.mypackage/com.mypackage.LogoutConfirmDialog
How can I get rid of the first 'titleonly' -dialog? Or how to prevent it from adding this dialog?
Thanks in advance!
Edit I added two printscreens of the Dialogs to clarify the situation:
First Dialog (this is what I want) https://i.stack.imgur.com/mxTT0.png
The second Dialog shows up when either of the buttons is clicked, or it's dismissed: https://i.stack.imgur.com/bmCk7.png