I have a basic question about service and notification, please

bsnqt

Active Member
Licensed User
Longtime User
I remember that I read somewhere in our forum (not in one thread, but in several threads) that to keep an app alive we have to use a notification that will stay in the notification bar. Some thing similar to the below:

B4X:
Dim Notification1 As Notification

'======================

Sub Service_Create

      Notification1.Initialize
      Notification1.Icon = "icon" 
      Notification1.AutoCancel= False
      Notification1.SetInfo("My app", "My app is running", Main)      
      Notification1.Notify(1)
      Notification1.OnGoingEvent = True

End Sub

I just wonder why there are many apps out there in Google Play that still can be alive without using this notification in the bar? They even can have option for the user to put or not put notification in the notif bar. How can they keep their app / service alive without using notification? Or we have limitation in B4A? Can you please enlight me more with this or I misunderstand something?

Thank you.

Best
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
Not sure, but a) you can create a transparent notification icon or b) you can set your service to not run in foreground. This way, it can get killed by the os, but you can even set it to start periodically using startServiceAt. I'm saying I'm not sure, cause I always set my services to foreground for good reasons.
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Not sure, but a) you can create a transparent notification icon or b) you can set your service to not run in foreground. This way, it can get killed by the os, but you can even set it to start periodically using startServiceAt. I'm saying I'm not sure, cause I always set my services to foreground for good reasons.

Thanks for sharing your experience, but I mean:

(a) those apps they even don't have a transparent notification (no notification at all) but are still alive (we can see that there are many of them: Task Killers, Phone Recorders, Apps Lockers etc.);

(b) I have to set my service in the foreground as my service is using PhoneStateListener it has to listen the call all the times. It is not performing a periodic tasks, but has to be alive permanently so I cannot use StartServiceAt.
 
Upvote 0

rabiuls

Member
Licensed User
Longtime User
@bsnqt, Hello,

Have you found the solution? If so ignore the rest of the message. I had problem like you before.

I made an app for my phone. The app is for blinking hardware key's back led at 5 seconds interval, for missed call or sms - until user unlocks the phone by sliding the screen lock. Many phone has this feature built-in that blinks a led for missed call, while my phone doesn't have it. It doesn't show any notification icon and uses "StartServiceAt".

Do you think, this may help you for your project?

Best regards.
 
Last edited:
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
@bsnqt, Hello,

Have you found the solution? If so ignore the rest of the message. I had problem like you before.

I made an app for my phone. The app is for blinking hardware key's back led at 5 seconds interval, for missed call or sms - until user unlocks the phone by sliding the screen lock. Many phone has this feature built-in that blinks a led for missed call, while my phone doesn't have it. It doesn't show any notification icon and uses "StartServiceAt".

Do you think, this may help you for your project?

Best regards.

I meant I am ok with the solution to use the notification plus calling the StartForeground.

B4X:
Service.StartForeground(1, Notification1)

But doing this it may lead me to put many notifications on the notification bar of the users' phone, as most of my apps will use the "permanent" service (like listening to phone call, sms receiving, etc) :) ... So it is really not nice to have many notifications there just because we want our service not being killed. And furthermore I really would like to know why other apps can do this (keep their app alive without using notification), but I can't.

So it is very interesting to know how you do it with your app. Can you share more? You wrote your app using B4A?

Thanks a lot.
 
Last edited:
Upvote 0

rabiuls

Member
Licensed User
Longtime User
Yes bsnqt, I wrote it with B4A. I used "StartServiceAt" and it is not killed. I don't know whether it is supposed to get killed. I am attaching the B4A project. Probably it will not blink the led on your phone, as different manufacturer makes it differently. You may play an audio or something like that for detecting missed call.

By the way, the code is not cleaned :) - I wish to make something more with it like call filter/blacklist in future.

Best regards.
 

Attachments

  • MissedCallAlert-Service-StartAt-v2.zip
    41.8 KB · Views: 290
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Yes bsnqt, I wrote it with B4A. I used "StartServiceAt" and it is not killed. I don't know whether it is supposed to get killed. I am attaching the B4A project. Probably it will not blink the led on your phone, as different manufacturer makes it differently. You may play an audio or something like that for detecting missed call.

By the way, the code is not cleaned :) - I wish to make something more with it like call filter/blacklist in future.

Best regards.

Hi rabiuls, thanks so much for sharing, I appreciate. I will learn more using your codes.
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
I would suggest a different approch

I od not like to work with the the state listener because it wont work when your service is killed and force you to set foreground wich force you to work with notification and force your process to be alive all the time and use system resources when y ou really need it only when a call is coming.
thats a lot of overhead on you as a developer and on the user

a better approch is to use the manifest to register to the right intents making the OS call your service when a call is coming, so no need to notification, no resources used unless a phone call is coming, pretty efficiant dont you think ?

see this thread (SMS related but the same concept) http://www.b4x.com/forum/basic4android-updates-questions/8862-sms-receive-problem.html

you need to register to the ACTION_PHONE_STATE_CHANGED if I understand what you are trying to do (remeber to add the permission)
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Yes that is true, I agree intent is also a good alternative method. I also learn to work on it.
 
Upvote 0
Top