2.0 Beta: It's not possible to store a reference to the Activity in a user class

corwin42

Expert
Licensed User
Longtime User
I tried to store a reference to the activity in a user class. It is not possible to Dim an Activity object.

B4X:
Sub Class_Globals
   Private mActivity as Activity
End Sub

Sub Initialize(Activity as Activity)
   mActivity = Activity
End Sub

gives follwing error:

B4X:
Compiling generated Java code.          Error
B4A line: 10
Private mActivity As Activity
javac 1.6.0_23
src\anywheresoftware\b4a\samples\actionlist\slidemenu.java:105: cannot find symbol
symbol  : constructor ActivityWrapper()
location: class anywheresoftware.b4a.objects.ActivityWrapper
_mactivity = new anywheresoftware.b4a.objects.ActivityWrapper();
             ^
1 error

So if you need access to the activity in a user class sub then you have to pass it always to the sub. I would love to do it only in the Initialize() sub.

I don't know if this is really a bug because Activities are very special objects but is there any possibility to directly access the activity from a user class?
 

pluton

Active Member
Licensed User
Longtime User
I'm new in classes but you can't do this I think

You can't name it Activity as Activity

B4X:
Sub Initialize(Activity as Activity)
   mActivity = Activity
End Sub

Am I right???
 
Upvote 0
Top