Android Question Bluetooth comunication module in background

TomKluz

Active Member
Licensed User
Hello,
I am still working with app using classic bluetooth comunication (arduino - android).
Until this app was simply using one page there was no problem at all. From the moment I use many pages (activities) the problem is that during changing a page streams are interrupted and I have to activate them again on another page (activity). Finally it works but I have to press connect button before entering every next page (activity).

Is it a way to make a bluetooth comunication module working constantly in background and supplying data to any activity if necessary ?

Thank you in advance
TomKluz
 

Peter Simpson

Expert
Licensed User
Longtime User
Are you using the starter service???

Also look at this example from Erel to try to keep it running in the background. The example is background tracking, but I presume that the principle is basically the same.
 
Upvote 0

TomKluz

Active Member
Licensed User
Hello,
Sorry for the late answer. I didn't got any email as before as an info about replyes.

No, I am not using starter service. A class problem is still a problem in front of me. I have to understan it first. Anyway I am going immediatelly
to the example pointed above.
 
Upvote 0

TomKluz

Active Member
Licensed User
Hello,
I have went throw begginers guide and Mr Erel's example "Bluetooth'.
So far my program flow was like this:
- Main module - serial ports inicjalsation and enabling
- Any other module - astreams inicjalisation and cloasing when leaved.
Entering of this module is possible only when we start from Main Module

Starter service due to description is always working. So, Should I put everything about comunication there + general data and treat them like
repository for all other modules ?
At the end: how to stop starter module ?
Is it enough just to add new module with a name starter and thats it as any other module ? Only a name is special ?

Kind regards
TomKluz
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
At the end: how to stop starter module ?
You should NOT stop the starter service manually

Is it enough just to add new module with a name starter and thats it as any other module ? Only a name is special ?

The starter service must be a Service.

 
Last edited:
Upvote 0

TomKluz

Active Member
Licensed User
Thank you
I have move everything regarding bluetooth connection into Starter (service) module. It starts at the beginning and work permanently.
It is possible to see data transmited from all streams in log panel durind entering all activitis in my app. There are in Starter module also
all public values declared to shate with other modules(activitis).
1. How to display a value from Starter in another activity ?
I have tryed to put a sub like this:
Sub DataMonitor
Label.text = Starter.Value 'Value declared as public in Starter
End Sub
Unfortunatelly the code after display performing first time goes to Resume and then back into Starter.
I don;t know how o keep it permanently in DataMonitor sub.
2. Is it possible to controll what is going in in Starter ?
For example switch off or on a task which Starter performs ?

Kind regards
TomKluz
 
Last edited:
Upvote 0

TomKluz

Active Member
Licensed User
Thank you for your attention.
OK. I will try to upload the sample. It will take some time
I am not getting any email when someone has answerd my question., as before.
Is it a change or some mistake ?

Kind regards
Tomasz Kluz
 
Upvote 0

TomKluz

Active Member
Licensed User
At last I can reed values from starter module. The trick was that after "edittext.text = starter.publictextvar" I had to place sleep (100). Then activity has started.
I have other question:s regarding:
- error management inside starter module.
So far I was trying to handle transmission errors using Astream_Error sub and it works in normal activity
In case of Starter I cannot got any info about error. Reading just stops and stays for a very long time.
Is it another way to handle transmission errors, or maybe I am doing it wrong ?
- If transmission brakes, is it possible to activate it again ? Restarting Starter without leaving app. ?

Thank you very much in advance
TomKluz

P.S.
After some trials I cannot effect StopService. In the log panel I am getting:
** Service (starter) Destroy (ignored)**
Eny suggestions please
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
So far I was trying to handle transmission errors using Astream_Error sub and it works in normal activity
In case of Starter I cannot got any info about error. Reading just stops and stays for a very long time.
It works exactly the same in the starter service.

If transmission brakes, is it possible to activate it again ? Restarting Starter without leaving app. ?
You should make the connection again. Don't stop or start the starter service yourself.

** Service (starter) Destroy (ignored)**
It is explained here: https://www.b4x.com/android/forum/threads/90546/#content
 
Upvote 0
Top