Reputation: 17051
Short story: My dialog is hidden when a specific activity is displayed. When other activities are showing, the dialog can be seen fine.
Long story: I have an activity which uses the following flags:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES);
It also uses the PROXIMITY_SCREEN_OFF_WAKE_LOCK
in order to turn off the screen when you put the phone against your face.
This activity is defined in the manifest as follows:
<activity
android:name=".ui.MyHidingActivity"
android:configChanges="orientation|screenSize"
android:launchMode="singleInstance"
android:windowSoftInputMode="stateHidden"></activity>
Now, when an event happens in the application I want to create and show this dialog:
KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("com.mycompany.myproject");
kl.disableKeyguard();
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "My_App");
wl.acquire();
final AlertDialog alertDialog = new AlertDialog.Builder(tabActivity).create();
alertDialog.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
alertDialog.setTitle("Incoming Event");
alertDialog.setMessage("You have an incoming event.");
alertDialog.show();
wl.release();
The dialog displays fine when any other activity is displayed, except for that MyHidingActivity
which hides the dialog for whatever reason. Any idea what may be the problem?
Upvotes: 1
Views: 1019
Reputation: 17051
OK I have found the solution.
The issue was in new AlertDialog.Builder(tabActivity).create()
where I pass in the main activity. This doesn't just use this activity as any old Context. The dialog is shown on top of that activity. But the MyHidingActivity is not the same activity as the main one so it hides both the main activity and the dialog it is attached to.
In order to fix this issue, you have to display the dialog on top of all other activities. And for that you have to:
AlertDialog.Builder(this).create()
(where "this" is my
application)Make the dialog a System dialog:
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
Upvotes: 3