Android Question Why Event is not activating at incoming call ?

ahmadalibeck

Member
Licensed User
Longtime User
I am trying to apply the code below, but it seems like the event is not rising so no message is shown at incoming call. I am using Samsun Galaxy S5, it is using Kitkat.

If can help, is there any thread shows what functions and features discontinued in Kitkat in general ?!

B4X:
Sub Process_Globals
    Dim PE As PhoneEvents
End Sub

Sub Service_Create
    PE.Initialize("PE")
End Sub

Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
 
    Msgbox(State,"Test")

End Sub
 

Straker

Active Member
Licensed User
Longtime User
Are you using that code in a code module? Code modules don't support events...
 
Upvote 0

ahmadalibeck

Member
Licensed User
Longtime User
No, this service module is called at Activity_Create in the Main module of the application

Below is the code in the Main module, where the services module is named "SPhone"

B4X:
Sub Globals
    Private ListView1 As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")
    If FirstTime Then StartService(SPhone)
End Sub
 
Last edited:
Upvote 0

ahmadalibeck

Member
Licensed User
Longtime User
Thanks for every one ..

Regarding activity visibility, it is visible during incoming call.

Here what I did. I installed the program, ran it, then I called the Phone, but no message appears.

I tried a toastmessage, not worked, i tested a listview adding line about the state, same.

:(
 
Upvote 0

ahmadalibeck

Member
Licensed User
Longtime User
To be completely clear, below are snapshots, no thing happened as a result.

1_online.jpg





2_online.jpg
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
I'm not completely sure, but I think that you cannot have a ToastMessage (or a MsgBox) in a Service. The service is 'invisible' by concept.
Try to add Log(State & "- " ...) and see the log

If you want toasmessages, you should CallSub a sub in your activity, which can perform a ToastMessage (if the Activity is in Foreground, of course)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Try to add Log(State & "- " ...) and see the log

It´s like @Erel already stated
You cannot call Msgbox from a service. Add a Log message and check the logs.

Ok. He is facing a MsgBox here. But i think it is valid for Toasts too.

Edit:

No, it isn´t

Code written in an activity module is paused once the activity is not visible.
So by only using activities it is not possible to run any code while your application is not visible.
Services life cycle is (almost) not affected by the current visible activity. This allows you to run tasks in the background.
Services usually use the status bar notifications to interact with the user. Services do not have any other visible elements. Services also cannot show any dialog (except of toast messages).
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
Thanks DonManfred.
So, ToastMessages work also in Services.

@ahmadalibeck
Do you see the 'Started Service' Toastmessage?
 
Upvote 0
Top