Sub IsActivity(obj As Object) As Boolean
If Not(obj Is Panel) Then Return False
Dim jo As JavaObject = obj
Dim parent As Object = jo.RunMethod("getParent", Null)
Return parent <> Null And (GetType(parent) = "android.widget.FrameLayout" Or _
GetType(parent) = "anywheresoftware.b4a.objects.IME$ExtendedBALayout")
End Sub
You can use this code:
B4X:Sub IsActivity(obj As Object) As Boolean If Not(obj Is Panel) Then Return False Dim jo As JavaObject = obj Dim parent As Object = jo.RunMethod("getParent", Null) Return parent <> Null And (GetType(parent) = "android.widget.FrameLayout" Or _ GetType(parent) = "anywheresoftware.b4a.objects.IME$ExtendedBALayout") End Sub
Sub Activity_Create(FirstTime As Boolean)
pnl.Initialize("")
Activity.AddView(pnl, 0, 0, 50dip, 50dip)
Dim Parent As Object = GetParent(pnl)
If Parent Is Activity Then
Log("Yes")
Else
Log("No")
End If
End Sub
Sub GetParent(v As View) As Object
Dim jobj = v As JavaObject
Return jobj.RunMethod("getParent", Null)
End Sub
I think it's because the parent is the actual activity you are calling it in. I suspect it won't work if the "parent" is from another activity. Anyway, i'm moving away from using multiple activities within in an app. I mainly needed this piece of code temporarily while testing. I would encourage others to do the same, especially to make your app more ready for other platforms. Another benefit is you can make use of a drawer much easier. Now if we could only get a template feature it would sure help in the process. Btw, how's things going with you? You probably noticed i was absent for quite a while. B4i kinda pulled me back inWell, if obj (#1) is an activity object, "is activity" works.
B4X:Sub Activity_Create(FirstTime As Boolean) pnl.Initialize("") Activity.AddView(pnl, 0, 0, 50dip, 50dip) Dim Parent As Object = GetParent(pnl) If Parent Is Activity Then Log("Yes") Else Log("No") End If End Sub
B4X:Sub GetParent(v As View) As Object Dim jobj = v As JavaObject Return jobj.RunMethod("getParent", Null) End Sub
Btw, how's things going with you? You probably noticed i was absent for quite a while. B4i kinda pulled me back in
I think that rarely you can use one Activity only, without going crazy with dozens of views and panels
So, welcome back
In your main activity you simply handle the showing/hiding of the form classes
No silly, all the events are handled within the class. You only call back the main activity if you need to, probably not much different than what you do now with inter-activity stuff.Good, become a B4i expert, so when I have released an Android app (2059 ), I will ask you to convert it to iOS.
... and write in the Main Activity all the code needed for "each Activity", including events. Uhm... mumble mumble