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 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
Your code as it is, is not clear. What is obj? I guess that you copied a small part of a larger code snippet. So it is impossible to say whether it is correct or not.
Public Sub IsActivity(v As View) As Boolean
Dim obj As Object
obj = GetParent(v)
If GetType(obj) = "android.widget.FrameLayout" Then
Return True
Else
Return False
End If
End Sub
The code you now posted is 99% correct (though you still didn't post the GetParent sub).
The only case where it will not work is if someone uses IME.AddHeightChangedEvent.
Well, 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
Well, 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
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 in
Actually it's quite easy and more flexible. You simply convert your activity to a class and have a panel within that class that you load your layout into. I'll post a skeleton class when i get to my comp. In your main activity you simply handle the showing/hiding of the form classes. It's basically how you need to do it in b4i so it's better to do it in b4a as well. Another benefit is you can create multi windows a lot easier. A good example would be spreadsheet pages.
I think i'll create a navigation class like the one in b4i to handle all the "page" stuff in b4a. Then it's just a matter of a few conditionals and b4a apps are pretty much ready for b4i. There's a great tool to significantly help convert b4a layouts to b4i. (Just wish it was a more drag and drop tool vs cmd line) Of course android is far superior to ios but unfortunately with around 30% of the market share i have no choice but to support it.
Thanks
Edit: I should add with classes vs activities, you don't have all the issues of recreating you activity everytime you switch between them (and saving state)
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.