Android Question Notification when app is close

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
I wrote an app that send a notification if the result of a query is not null.
How can I send this notification, even if the app is close and it isn't in the task manager?
 

Straker

Active Member
Licensed User
Longtime User
If the app is not running, the is no code to be executed, therefore is impossible to show a notification.
BUT if you have a service, from the service you can fire a notification. A service is the normal place for a notification. For example in your phone you receive a notification when you receive an email when your email app is not running. There is a service which periodically check for new emails.

See this Erel's tutorial http://www.b4x.com/android/forum/threads/7542/#content and have a look at the examples.
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
I have to use a Sticky Service? What I have to do, after setting the attribute
#StartCommandReturnValue: android.app.Service.START_STICKY?
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
Just start with a normal service. When the normal service works, the you may decide if in your case is better a sticky or normal.
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
But I don't want to send a normal notification. I need to set the value of this, by the result of the query
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
...which is a normal notification. A message at the top of the phone with an icon, a title and a message. Or something better if you use some specialized library.
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
You can find a lot of examples.
The Erel's examples I already mentioned in post #2 are very good.
You can also see the example I made for services and sockets in http://www.b4x.com/android/forum/threads/45017/#content which is extensively commented out, most of all from programmers coming from vb6
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
In these example I can't find any reference to Sticky service
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
Why sticky?
I mean, a service is a service. It can be standard, or StartForeground or Sticky but at the end they are the same.
The differences are that a StartForeground services has an icon on the task bar (let's say is not invisible) and is good for services that performs long running operation (download a huge file for example). Sticky services are more persistent, normally the O.S. doesn't kill the sticky services and if it kills it, it will be recreated as soon as possible by the same o.s.

So, back to you, if you really need/want a sticky service, see the Erel tutorial http://www.b4x.com/android/forum/threads/27065/#content
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
In these example I can't find any reference to Sticky service

Have you ever tried to search the forum instead of assuming ALL your problems are handled in ONE example?

snap002.png
 
Upvote 0
Top