Android Question Question: How to get value or text from activity to service module?

IslamQabel

Active Member
Licensed User
Longtime User
Dear Erel and all members:

i am designing a program that has two module (Activity & service), Actually my Target is ....the user enter the number in edittext object in activity module and then i am using PhoneStateChanged to watch phone status...Ringing or Idle or offhook....When this number which is entered in the activity module edit text call me ....the program should compare the entered number in activity module with the incoming number in service module, if they match start activity....How to do that? i tried it many times but i failed to do that

Anyone help please
 

IslamQabel

Active Member
Licensed User
Longtime User
Hi Erel:

I will explain the problem....

I made edit text in Activity module "Dim EditText1 As EditText" ......and also in Service module "Dim EditText1 As EditText"...When i run the app i just enter the number of phone "123456789" for example......and start service module from Activity....
In service module "Listening to incoming calls.....by the following code

Sub PE_PhoneStateChanged(State As String,IncomingNumber As String, Intent As Intent)
If State="IDLE" Then
ToastMessageShow("Phone is IDLE MODE.",False)

End If

If State="RINGING" Then ' Ringing state.
ToastMessageShow("Phone is RINGING.",False)
ToastMessageShow("Phone is RINGING of Number"& IncomingNumber,False)

If IncomingNumber=Edittext1.Text Then
ToastMessageShow("John calling you.",False)
End If


StartActivity("Main")

End If

If State="OFFHOOK" Then ' Off the hook state.
ToastMessageShow("Phone is OFFHOOK.",False)

End If

End Sub

The Problem that "JOHN calling you didn't displayed why???

Please help

Thanks
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User

Attachments

  • AutoAnswer2 Example.zip
    57.5 KB · Views: 300
Last edited:
Upvote 0

IslamQabel

Active Member
Licensed User
Longtime User
Works Perfect ..................Thanks a lot Mangojack........really very helpful example and gained some new info
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
your welcome ...
 
Upvote 0

IslamQabel

Active Member
Licensed User
Longtime User
Now, if want to do the same between two activities.....How to do it?
I tried but unfortunately it did not work like Activity and service module
 
Upvote 0

IslamQabel

Active Member
Licensed User
Longtime User
I think CallSubDealyed is not enough because it has no arguments but i would ask what is the meaning of Argument object in callsubdelayed2 & 3..............i think CallSubDelayed2&3 may help me but i do know how to use them to transfer text value or image
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim teststring As String
teststring = "Bla bla bla"
CallSubDelayed2(two,"showtext",teststring)

Dim teststring As String
teststring = "Your creditcard is charged by "
Dim testnumber As Double
testnumber = 1.25
CallSubDelayed3(two,"showtextandnumber",teststring,testnumber)

and in activity "two" you have for example

B4X:
Sub showtext(text As String)
    ToastMessageShow("Text: "&text, True)   
End Sub
Sub showtextandnumber(text As String, number As Double)
    ToastMessageShow("Text: "&text&" Number: "&number, True)   
End Sub

you can send any type of object over this way

B4X:
Dim retmap As Map
retmap.Initialize
retmap.Put("tag","TagValue"&i)
retmap.Put("itemID","ItemID"&i)
retmap.Put("name","ItemName"&i)
retmap.Put("line1","This is line 1")
retmap.Put("line2","This is line 2")
CallSubDelayed2(two,"showmap",retmap)

B4X:
Sub showmap(test As Map)
    ToastMessageShow("Map: "&test, True)   
End Sub
 
Upvote 0

IslamQabel

Active Member
Licensed User
Longtime User
Dear DonManfred...Thanks a lot for your help.........i would like to ask
Dim teststring As String
teststring = "Bla bla bla"
CallSubDelayed2(two,"showtext",teststring).......
....The Argument here is teststring Ok....
Now how it will realized in activity two in
Sub showtext(text AsString)
ToastMessageShow("Text: "&text, True)
End Sub

i.e. What is the relation between text and teststring ? this is which make myself confused.... all i understand that "text" & "teststring" are string objects
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
It´s nothing more than i used the name teststring in act 1 and the name of the parameter in act 2 is text. But it is the contents of teststring which will arrive in act2 under the name text.

They are both strings, yes. But you must understand how parameters works in b4a... i dont "give" a variableNAME to a sub called with callsubdelayed. I give an object. In this case it is a STRING...

The names can diff between act1 where they are DIMmed and the name which is used in the sub ShowText... The point is that the String-Object is given to this sub. Not its name.

Maybe such situations are easier to understand when you have worked with b4a more.

If i name both to text then it would work also, yes. But if some error occurs with the string text i must look at act1 AND act 2 to find the error.

In my -working - example i have used two different names.
if i have an error with text then i only look at act1 cause i have this name only there.
if i have an error with teststring then i only look at act2 cause i have this name only there.

In fact; i´m faster in debugging a error...

I do that automatically without thinking over it. It´s routine i learned in the last 25 years of programming :)
 
Last edited:
Upvote 0

IslamQabel

Active Member
Licensed User
Longtime User
Thanks a lot ..........Understood it and got it...Works perfect.....I also success ed to transfer image ...........here is the code

In main:

B4X:
Private ImageView1 As ImageView
Sub ImageView1_Click
    ImageView1.SetBackgroundImage(LoadBitmap(File.DirRootExternal & "/DCIM/Camera","photo.jpg"))
    ImageView2.Bitmap=ImageView1.Bitmap
    CallSubDelayed2(activity2,"Photoo",ImageView1)
End Sub


In Activity2:
B4X:
Private ImageView1 As ImageView
Sub photoo(Image As ImageView)
    ImageView1.Bitmap=Image.Bitmap

End Sub

I think i understand the concept of transfer, the most important thing that you transfer for the same object type...try me code
 
Upvote 0

IslamQabel

Active Member
Licensed User
Longtime User
and i understand what you mean about different names declaring..........Do not worry i am an old programmer since 1998....beginning with BASIC....MATLAB....C......Micro-controllers..........then the amazing BASIC4Android (still beginner)............and i love programing so much....
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

IslamQabel

Active Member
Licensed User
Longtime User
Now.... a final problem i am facing now..........After loading images and text values between different activities when i close the application or shutdown my mobile.........All loaded images are lost so i have to load them again.....................Now How to keep them without losing them after closing the application or shut down the mobile..................it is important issue
Apologize for asking a lot of questions
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Islam .. Here is the CallSubDelayed example we discussed. it uses CallSubDelayed3 and passes 2 argumuments (edittext and ImageView).
It appears you have solved your problem , but it may be of use.

Agree with Don . Read up on StateManager.

Cheers
 

Attachments

  • CallSubDelayed Example.zip
    26.2 KB · Views: 255
Upvote 0
Top