Android Question Proximity sensor and running in service issue

Dear B4A programmers, dear founder of B4A,
I have tried to adapt several pieces of codes available on this forum to allow Me to use mi Proximity sensor to initiate speak time when my screen is turned off. I have allready successfully tried app on Activity. Sensor react as it should, and app speak current time. But when I have turned The screen off, app did not speak The time.
So I have tried to implement working in background when device screen have been turned off by using service.
Result is very unpleasant.
When I put my hand near of The Proximity sensor and my screen is turned on, app auto terminate and focus get in to home screen.
When The screen have been turned off, crash of app do not occur, but sure, app do not speak The time.
So app speak only when code resides in A activity, very probably also in B4X pages.
Why I want this background app?
Because I want to save The life span of hardware button on my phone which I must press to get iinformation about The current time.
Modern phones are very non easy to repair at home, changing hardware buttons is very un easy.
Thank you for your help.
 

Attachments

  • proximity.zip
    9.7 KB · Views: 54
Oh you are wonderful dear B4A founder. Now, code work. And if Android core will auto close some of its threads, I will do my best to add Foreground service and partial Wakelock to prevent Android from killing The background app. Thank you dear founder, that you have created B4A. It is really The best and The most stable and reliable Basic based programming language for Android and not only for this platform on The world. So very well done and thank you.
 
Upvote 0
And here is fully functioning code. I will observe how long app will run and if it will be aautoterminated. If it will not occur after 2 hours, I will even not be forced to use Foreground service and notification and partial Wakelock.
 

Attachments

  • Proximity_pages.zip
    10 KB · Views: 67
Upvote 0
Dear Real, your soul is full of programmers wisdom. Please, could you try to give Me a piece of advice? Why even foreground service do not allow Me to use The proximity sensor when my scren have been turned off?
I have really made my best. I Am sending modified .zip archive with foreground service. It really do not work.
What should I try?
Pndaudioexoplayer library work by this way, radio play many many hours. But why powerful Android core block The proximity sensor to be usable in background?
Should I add The infinite loop to The Running sub inside sluzba.bas service file?
I have also other idea for background task. Ticking clock which will automatically speak The time and ticking sound will occur every one Second. So I would like to become professional in background tasks.
 

Attachments

  • Proximity_pages.zip
    10.6 KB · Views: 70
Upvote 0
Important and very sad fact is, that it is really manner of Android power management. Your special Java code which allow to type Basic language command is 100 % professionally programmed and B4A app can even run for many days even on system with only 160 MB of free RAm without random crashes. I can only tell you dear Erel very well done for your programmers work. I Am also aware, that every Android release and phone manufacturers can customize or add more power management services which affect on background tasks behaviour. I will now try The proximity app on my older Tablet with Android 6.0. I will also try The ignore battery optimisations routine which recall whole battery dialog to allow add some app to White list for ignoring battery optimisations. BUt if it will not help, I will be very probably forced to give it up. I will be hoping, that if sound chip will play tick sound every one Second, that it will not kill The process.
 
Upvote 0
Top