Android Question How to make the app working in background?

Mattiaf

Active Member
Licensed User
Hi, today it's my first day in b4x ecosystem and since I know a bit of vb.net, it has been quite exciting to discover.
So, I'm working for a personal utility which parse a crypto price from an exchange price.
Thanks to all the topics I've been able to code this and run it correctly on my samsung s20+ with android 12:


B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private Button1 As Button
    Private Label1 As Label
    Private timer1 As Timer
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layout")
    timer1.Initialize("Timer1", 100)
timer1.Enabled=True  
    End Sub
Sub Button1_Click
timer1.Enabled=False
End Sub
Sub timer1_tick
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://api.hotbit.io/api/v1/market.last?market=KIBA/USDT")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
        Dim parser As JSONParser
        parser.Initialize(j.GetString)
        Dim root As Map = parser.NextObject
        Dim result As String = root.Get("result")
        Label1.Text= result
    End If
    j.Release
End Sub

The fact is now I'm looking to make it works in background and many recents topic are redirecting me to This topic but if I need to be honest, It is 3 ys old and I don't know if that is all I need. Should just insert that line in the app.manifest? if so, is app.manifest on "Project > Manifest Editor"?
I'm just looking to make it works in background and after that I'll send push notifications or play a .mp3 since the app will be an important price alert.
I also read about "ignore battery saving" and "allow data on background" but I hope I can just set them straight from the phone settings.
Thanks,
Mattia
 
Last edited:

Mattiaf

Active Member
Licensed User
Thanks, I've answered before but it seems someone deleted my answer.. Just said Thanks for your help and if it s possible to use an edit box instead of "0.000026". If it's offtopic, please tell me.
Still thanks aeric
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Thanks, I've answered before but it seems someone deleted my answer.. Just said Thanks for your help and if it s possible to use an edit box instead of "0.000026". If it's offtopic, please tell me.
Still thanks aeric
Yes, it is possible to get the input from EditText. When you do comparison then you should convert it first to Double.

Is my sample meeting what you expect?
The rest I will leave it to you to improve the app.
 
Upvote 0
Top