Ciao ragazzi, sto usando il codice postato da Luca nel topic Creare un semplice price alert senza utilizzare server
su main:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
sul modulo di servizio MyService
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Le righe commentate con 'fatte da me sono appunto scritte da me ( ma vah??!) e quello che sto cercando di fare è usare la edittext Price su "If result > "0.00002884" del modulo di servizio MyService tipo If result > Price.text
Ho provato a dichiarare Private Price As EditText in MyService su process globals ma dice "MyService - 9: Non è possibile accedere ad oggetti di Activity dalla routine Process_Globals." e se provo a creare l'evento textchanged dall'editor di MyService, mi dice che il modulo corrente non supporta eventi di layouts.
Come posso risolvere?
Vi ringrazio anticipatamente
			
			su main:
			
				B4X:
			
		
		
		Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    
End Sub
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private btnStop As Button
    Private btnStart As Button
    Private price As EditText ' fatto da me
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layMain")
  price.Text= File.ReadString(File.DirInternal,"1.txt") ' fatto da me
End Sub
Private Sub btnStart_Click
    btnStart.Enabled = False
    CallSubDelayed(MyService, "Start")
    btnStop.Enabled = True
End Sub
Private Sub btnStop_Click
    btnStop.Enabled = False
    CallSubDelayed(MyService, "Stop")
    btnStart.Enabled = True
End Sub
Private Sub Price_TextChanged (Old As String, New As String)  ' fatto da me
   File.WriteString(File.DirInternal, "1.txt", price.Text) ' fatto da me
'End Subsul modulo di servizio MyService
			
				B4X:
			
		
		
		Sub Process_Globals
    Private nid As Int = 1
    Private lock As PhoneWakeState
    Private  timer1 As Timer
    'Private price As EditText ' fatto da me ... ?!?!
End Sub
Sub Service_Create
    lock.PartialLock
    timer1.Initialize("Timer1", 3000)
End Sub
Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground
End Sub
Public Sub Start
    Service.StartForeground(nid, CreateNotification("HotBit attiva"))
    timer1.Enabled = True
End Sub
Public Sub Stop
    timer1.Enabled = False
    Service.StopForeground(nid)
End Sub
Sub CreateNotification (Body As String) As Notification
    Dim notification As Notification
    notification.Initialize2(notification.IMPORTANCE_HIGH)
    notification.Icon = "icon"
    notification.SetInfo("App attiva", Body, Main)
    Return notification
End Sub
Sub Service_Destroy
    lock.ReleasePartialLock
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")
        Log(result)
    End If
    If result > "0.0002884"  Then
        Dim n As Notification = CreateNotification($"Prezzo superiore a "$ + result)
        n.Notify(nid)
    End If
    j.Release
End SubLe righe commentate con 'fatte da me sono appunto scritte da me ( ma vah??!) e quello che sto cercando di fare è usare la edittext Price su "If result > "0.00002884" del modulo di servizio MyService tipo If result > Price.text
Ho provato a dichiarare Private Price As EditText in MyService su process globals ma dice "MyService - 9: Non è possibile accedere ad oggetti di Activity dalla routine Process_Globals." e se provo a creare l'evento textchanged dall'editor di MyService, mi dice che il modulo corrente non supporta eventi di layouts.
Come posso risolvere?
Vi ringrazio anticipatamente
 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		