0

What is the way to create a popup screen that's opened from a background service while app is not running in foreground?

Refer to the Skype answer-reject dialog when there's an incoming call:

enter image description here

I have a background service that always runs even the app is not visible to user, but how can I pop up a screen like in the image from that service?

Update:

I am looking for the term used for this kind of screens, is it a regular activity started from the service, or some form of "notification" ?

AlphaQ
  • 656
  • 8
  • 18
uylmz
  • 1,480
  • 2
  • 23
  • 44
  • 1
    I wouldn't answer a call from him either. But you should probably edit to add the code you are trying to use and what is/isn't working. Otherwise, this question is off-topic as it is too broad and just asking for code. – codeMagic Dec 08 '16 at 14:00
  • The recommended way of doing this is to use [a heads-up `Notification`](https://developer.android.com/guide/topics/ui/notifiers/notifications.html#Heads-up). – CommonsWare Dec 08 '16 at 14:01
  • I am looking for the term for this kind of screens, is it a regular activity started from the service, or some other "notification" ? – uylmz Dec 08 '16 at 14:01
  • try links : https://github.com/everythingandroid/android-smspopup https://github.com/selmantayyar/Custom-SMS-Popup – Deepak Sachdeva Dec 08 '16 at 14:03
  • @CommonsWare heads-up notifications doesn't show up when screen is closed, am not right? You wouldn't want to miss a call because screen is closed :) – uylmz Dec 08 '16 at 14:06
  • @Reek: "heads-up notifications doesn't show up when screen is closed" -- I do not know what "screen is closed" means. If you mean "screen is off", notifications display on the lockscreen on Android 5.0+, and your approach will not be able to display on the lockscreen at all. – CommonsWare Dec 08 '16 at 14:11
  • @CommonsWare My bad, thanks. So is it not possible to achieve this with sdk older than 5.0? – uylmz Dec 08 '16 at 14:13
  • @Reek: To be honest, I forget if there were options for this prior to Android 5.0. – CommonsWare Dec 08 '16 at 14:24
  • There is the SYSTEM_ALERT_WINDOW permission to start an activity that may overlay the lock screen too. Have your tried this? – Jonas Köritz Dec 08 '16 at 15:52
  • https://stackoverflow.com/a/29804684/2149195 – RBK Sep 12 '17 at 13:35

1 Answers1

1

This popup shows exactly that.

You can start an Activity with:

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

Do Read: If I can remember properly, I have read somehwere that it is against the Android guidline of using popup from a service. It recommends using a Notification service.

AlphaQ
  • 656
  • 8
  • 18
  • so skype or any other real time communication app is against google guidelines? I guess this case must be an exception. – uylmz Dec 08 '16 at 14:10
  • Using **a *popup* from service** is against it. Using an `Activity` is recommended. See [this](http://stackoverflow.com/questions/7918571/how-to-display-a-dialog-from-a-service/7918720#7918720). – AlphaQ Dec 08 '16 at 14:12