Android Question How to pass a value to a class?

incendio

Well-Known Member
Licensed User
Longtime User
Hello guys,

I have an activity (activity A), that initialized a class.

In this class, there is another call to a sub in other activity (activity B), the class using CallSubDelayed to call a sub in activity B.

Activity B waiting input from user and after finished, values from user passed to the class using CallSubDelayed, but the problem is, values didn't pass.

On log window, there is a message : Object context is paused. Ignoring CallSubDelayed.

I know that the object that initialized the class , which is activity A, is paused.

Class need to wait user finished input values in activity B, before continuing proses.

Codes in activity A
B4X:
Sub btn_click
    MyClass.Initialiazed(Activity,Me,"My_Class_Done")
End Sub

Sub my_Class_Done(Val() as String)
   Log(Val(0))
   Log(Val(1))
   Log(Val(2))
End Sub

Codes in MyClass
B4X:
Sub lbl_click
   Private m as map
   m.Initialize
   m.Put("CallFrom",Me)
   m.Put("Sub2Call","Dpt_Rsl")
   CallSubDelayed2(ActivityB,"Show",m)
End Sub

Sub Dpt_Rsl(Val() as String)
    IdDpt = Val(0)
    txtCnt.RequestFocus
End Sub

Codes in activity B
B4X:
Sub btnOK_click
   Private Val(3) as String
   Val(0) = 1
   Val(1) = "ABC"
   Val(2) = "test"
   CallSubDelayed2(MyClass,"Dpt_Rsl",Val) 'this sub in Myclass never called
End Sub

So, is there a way to pass value in activity B after user input finished and then pass those values to the Myclass?
 
Last edited:

ronovar

Active Member
Licensed User
Longtime User
Yes, you can send global values to another activity. Let's say we have Main Activity and Download Activity.

In Main Activity declare global variable: (for example global variable name is Test)

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Test As String
End Sub

Next in Main Activity add value to your global variable Testin this example we add value "How Are You Today?")

Sub Download()
Test = "How Are You Today?"
End Sub


Now to get Test Value in another activity so in Download Activity you just call the name of previus activity that holds global variable and you get value(for example):

Download Activity is this:

Log(Main.Test) ' OUTPUTS - How Are You Today? From Main Global Variable Test.

How you get the point?
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Thanks for your replied, but values only not enough, need to know when the activity finished.
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
If i understand you correctly you want to know when current activity is finished you can get this info from current module. So when activity is finished you get in this sub in finished activity to add your code what to do next when current activity is finished:

B4X:
Sub Activity_Pause (UserClosed As Boolean)
   'YOUR CODE HERE WHEN THIS ACTIVITY IS FINISHED
End Sub
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Sorry, may be I am not clearly stated my problem.

See again post #1, I have edited again to make it more clear.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
The simplest solution is to initialize the classes from the starter service. This way they will never be paused.
For now, due to time limit, I abandoned class and moved the codes from class to activity.

Thanks anyway for the hints.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…