service crash

nico78

Active Member
Licensed User
Longtime User
Hello,

i try to event incoming call with a service but the application crash

Here my code:
B4X:
'Activity module
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.

   Dim Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   activity.LoadLayout("test")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

      
Sub Button1_Click
   StartService(call)
End Sub

B4X:
'Service module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim PE As PhoneEvents
   '   Dim PhoneId As Phoneid --> unknown?
End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)


'   PE.InitializeWithPhoneState("PE", PhoneId) --> unknown?
   PE.Initialize("PE")
 
End Sub

Sub Service_Destroy

End Sub

Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
   Log(state)
   If state="RINGING" Then
      Msgbox(IncomingNumber,"")
   End If
End Sub
 

ZJP

Active Member
Licensed User
Longtime User
Msgbox is prohibited in a service.

B4X:
Sub Process_Globals
   ' Phone Event
   Dim PE As PhoneEvents
End Sub
Sub Service_Create
   PE.Initialize("PE")
End Sub
'
Sub Service_Start
End Sub
'
Sub Service_Destroy
End Sub
' Phone event

Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
   Log(state)
   If state="RINGING" Then
      ToastMessageShow(IncomingNumber,True)
   End If
End Sub

JP
 
Upvote 0

nico78

Active Member
Licensed User
Longtime User
InitializeWithPhoneState is unknown and phoneid also, I realized that it work if I make:
Sub Service_Start -> work
Sub Service_Start (StartingIntent As Intent) -> doesn't work

Yet Sub Service_Start (StartingIntent As Intent) is written automatically when I add the service with the IDE

It Is there an explanation?

[EDIT]
ok ZJP, but why IDE write --> Sub Service_Start (StartingIntent As Intent) ?
 
Last edited:
Upvote 0

ZJP

Active Member
Licensed User
Longtime User
I had not noticed this before. New parameters of version 1.60. Important for widgets.

JP
 
Upvote 0

KashMalaga

Member
Licensed User
Longtime User
Msgbox is prohibited in a service.

B4X:
Sub Process_Globals
   ' Phone Event
   Dim PE As PhoneEvents
End Sub
Sub Service_Create
   PE.Initialize("PE")
End Sub
'
Sub Service_Start
End Sub
'
Sub Service_Destroy
End Sub
' Phone event

Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
   Log(state)
   If state="RINGING" Then
      ToastMessageShow(IncomingNumber,True)
   End If
End Sub

JP

Im using that and doesnt do anything :confused:
 
Upvote 0

KashMalaga

Member
Licensed User
Longtime User
Have you started the service?

Thanks for the answer Erel, i solved. My problem was in inicialized phonestatemaneger you can use a variable that contains the value of phoneid, you must to use directy the name of the variable declare to the object.
 
Upvote 0
Top