0

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.

ofir_aghai
  • 3,017
  • 1
  • 37
  • 43

1 Answers1

2

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

codeMagic
  • 44,549
  • 13
  • 77
  • 93
  • there is a sample code how to do it? i didnt understand it well.. i create one more activity with that line in Manifest: android:theme="@android:style/Theme.Dialog" but it still not show nothing when i go to the homescreen – ofir_aghai Aug 14 '13 at 20:29
  • Which part don't you understand? To make the `Activity` look like a `Dialog` you just need to add that code to your `Activity` in the `manifest`. If you want to show it when the app isn't in the foreground then you want to use a `BroadcastReceiver` or have a `Service` running in the background. I don't know exactly what you are looking for but whichever you need there are a lot of examples and tutorials on The Google and SO – codeMagic Aug 14 '13 at 20:31
  • i try it but i cant success to prompt to user something when my app is on the background.. even after i put the line to the Manifest. there is a way to do it? – ofir_aghai Aug 14 '13 at 21:14
  • Did you try to implement a `BroadcastReceiver` as I suggested? I don't know what action you are expecting to prompt the user – codeMagic Aug 15 '13 at 01:17
  • i want to reminde the user to do something, so when my app is at the background (or if it's imposible.. even when my app killed) i want to write on the screen a message with 2 options. – ofir_aghai Aug 15 '13 at 08:19
  • like i wrote before.. similarly to clock-alarm – ofir_aghai Aug 15 '13 at 08:27
  • Then you want to look at [AlarmManager](http://developer.android.com/reference/android/app/AlarmManager.html). [And check here](http://stackoverflow.com/questions/4459058/alarm-manager-example) – codeMagic Aug 15 '13 at 11:29