Questions on Reflection

leongcc

Member
Licensed User
Longtime User
I am trying to get used to Reflection.

1) This is an experimental program that gets a "java.lang.ClassNotFoundException". Can someone point out my mistake.
B4X:
Dim  r As Reflector
Dim args(1) As Object    
args(0) = 5000
Dim Types(2) As String     
Types(0) = "java.lang.long"
r.RunStaticMethod("SystemClock", "sleep", args, Types)

2) The wiki for Reflection has the following statement appearing in several places:
Protected and private methods may be accessed if allowed by any security manager which may be present.
I am curious what security manager would allow access to private methods. Is this a hint that there is an undocumented "AllowRunPrivateMethod" function in Reflection ?
 

leongcc

Member
Licensed User
Longtime User
Thanks for the reply.

1) I have tried this already, same error generated. I have also checked that android.os.Bundle is imported. Please advise if there is any place I should check.
B4X:
r.RunStaticMethod("android.os.SystemClock", "sleep", args, Types)

2) Android does not allow calling private method of system class.
eg. private method setPin() in class BluetoothDevice.
So I think the wiki and you mean the private methods of my/another applications?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1) The size of Types is 2 instead of 1.
Note that you can write it like this:
B4X:
r.RunStaticMethod("android.os.SystemClock", "sleep", Array As Object(5000), _|
 Array As String("java.lang.long")

Sleeping for 5 seconds may cause an ANR dialog to appear. There is no good reason to block the main thread for 5 seconds.

2) I haven't tried to call this method. Though if there is any error it is not related to the reflection call.
 
Upvote 0
Top