0

I learned that following is Overview screen.

enter image description here

I clicked the dialer and dialed a number and then swiped the dialer to the right.

But still the call is on like this.

enter image description here

How is this done?

I am a newbie to Android programming. I am thinking if they had used a back ground thread or a separate service or something else, so that it is never killed accidentally. How is this done?

Please help me. Thanks.

sofs1
  • 3,834
  • 11
  • 51
  • 89

1 Answers1

0

I believe it is using the Android foreground service. You can checkout how to run it in the doc: https://developer.android.com/guide/components/services.html#Foreground

The difference of foreground from background service is when phone is low on memory, system will not automatically close it to release memory, it should be closed manually by user, which is why you need to have a notification as a way for user to close it when you first create it.

Jeff Hoang
  • 68
  • 6
  • could you take look at my question http://stackoverflow.com/questions/41217819/android-app-needs-not-to-be-wiped-from-memory – Mr.Popular Dec 21 '16 at 04:57
  • @Nhat At the same time, among the notifications, I am able to swipe notifications like "Screenshot", but not the Email or the call dialed as shown in the pic. Is it also by using foreground services? – sofs1 Dec 21 '16 at 05:01
  • yeah if you use StartForground(id, notification) you will have a notication like you said – Mr.Popular Dec 21 '16 at 05:06
  • still some devices can remove your ongoing notification as well your service if you clear your recent items.. I am working on it to solve.. but still i cant.. If you find a solution let me know man.. I would be a great help – Mr.Popular Dec 21 '16 at 05:18
  • @user3705478 Yes, because the Screenshot notification is not generated by (and tied to) any foreground service, so it can be dismissed, just like a new message notification. – Jeff Hoang Dec 21 '16 at 05:33
  • @Mr.Popular I am not sure what you need, but if all you need is a running service without caring about the app being open (either in recent list or on foreground), you can just create a background service with START_STICKY and also call startService() on device boot, then your service is up all the time (if the device memory is enough to run it, otherwise system will close it to release memory, but will restart it when avaiable). – Jeff Hoang Dec 21 '16 at 05:39
  • @Mr.Popular What you mentioned of Facebook and Whatsapp is not a receiver, it's a push notification from their server to the client app on the phone. You can take a look at GCM to implement this https://developers.google.com/cloud-messaging/android/client Hope it helps. – Jeff Hoang Dec 21 '16 at 05:42
  • @NhatHoang a normal service without foreground notification on my device easily destroyed by swiping the clear recent apps and never restart itselft.. i am returning START_STICKY from onStartCommand.. is there anything else i shud do ??? – Mr.Popular Dec 21 '16 at 06:17
  • Hi, I oversaw this reply, maybe you have already figured this out, you should set the Notification flag to FLAG_NO_CLEAR in order to avoid user swiping it. – Jeff Hoang Jan 12 '17 at 03:52