Android Question Make App run in background?

RishiKumar2210

Active Member
Hi Guys. I have created a project like an alarm clock. In the alarm clock, we have to set a time to ring a tone(mp3). But in my case. I have to set a time interval that too for multiple times. For Ex. I have set two time intervals 1 minute and 5 minutes. I want to ring an alarm after 1 minute from now for the first time, then I have to ring the alarm for a second time after 5 minutes from the ring rang the first time(Ex. 10.00A.M, 10.01 A.M(First Ring), 10.06 A.M(Second Ring). It works fine when the user is not closing the app. but when the user closes or minimizes it. It is not working. I want to make this task work in the background. how to do this? Here is My Project attached. What changes do I need to make? is there any line i need to make change in starter module in these lines?
B4X:
Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.

End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub
 

Attachments

  • Alarm.zip
    78 KB · Views: 54

RishiKumar2210

Active Member
Hi. I asked this question one week ago, but I still haven't received an answer. What is the reason? There is no solution for this thread or anything else. Thanks in advance.
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
Look into Receivers- You would set a receiver to fire in 5 minutes (give or take, they can be a little amount of time out depending on other tasks happening at the time).
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
It appears you are using your receiver module as a standard class which works ok when your app is in the foreground only.

The point of a receiver is to sit there in the background until a certain time then it gets launched. They need setting up differently to how you are using them.

Examine the attached file, hopefully there will be enough there to get you going.

I noticed though that in your code you can set alarms for just a few seconds - Receivers won't fire that often. Even one a minute is really pushing things. Your version of B4A is not up to date enough. Is there a reason you haven't upgraded? It's likely worth your while.
 

Attachments

  • ReceiverDemo.zip
    12.2 KB · Views: 44
Last edited:
Upvote 0

RishiKumar2210

Active Member
Hi, @John Naylor . I tried to run it on my B4A Version, but it shows some error in this line
B4X:
StartReceiverAt (MyReceiver, t, True)
and also in the manifest editor. Here is my error msg
B4X:
Error parsing manifest script:<br />Module startupreceiver_br not found (Manifest Editor)
StartupReceiver - 21: Undeclared variable 'startreceiverat' is used before it was assigned any value.
MyReceiver - 40: Undeclared variable 'startreceiverat' is used before it was assigned any value.
B4XMainPage - 37: Undeclared variable 'startreceiverat' is used before it was assigned any value.
B4XMainPage - 36: Unused variable 't'. (warning #9)
MyReceiver - 39: Unused variable 't'. (warning #9)
StartupReceiver - 20: Unused variable 't'. (warning #9)
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
You will need to be running the up to date B4A
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…