How to prompt to user an alert dialog but not when

2019-03-05 09:19发布

问题:

i want to show the user an alert dialog message, that he can choose yes/no but i want to do that automatical even and mainly when my app is not forground,

like clock alarm, that can jump up to screen in any situation (even if user in call)..

how to do that? i succeed to do alert.. but its came up just when my app is forground :/ using this guide: http://www.androidhive.info/2011/09/how-to-show-alert-dialog-in-android/

please help me, thank's.

回答1:

You can't, AFAIK, a Dialog needs an Activity. An option you have that may satisfy your needs is to create an Activity with a Dialog Theme and call this in a Receiver. All you need to do to make it look like an AlertDialog is to add

android:theme="@android:style/Theme.Dialog"

to the <activity> tag in the manifest.

BroadcastReceiver