use Activity object in a class

melamoud

Active Member
Licensed User
Longtime User
I'm writing a code inside a class and I need to run this line
B4X:
Dim nd As ClsExplorer   
'nd.Initialize(Activity, File.DirRootExternal,"",True,True,"Ok")   
nd.Initialize(Main, File.DirRootExternal,"",True,True,"Ok")

but I get a strange error from B4a something about needing layout for activity wrapper

when this line (the first one in comment) running inside Main no problems)

thanks
 

melamoud

Active Member
Licensed User
Longtime User
B4X:
Compiling code.                         0.46
Compiling layouts code.                 0.00
Generating R file.                      2.79
Compiling generated Java code.          Error
B4A line: 123
nd.Initialize(Main, File.DirRootExternal,\
javac 1.7.0_07
src\appsright\musicnotifier\foldersmanager.java:86: error: inconvertible types
_nd._initialize(ba,(anywheresoftware.b4a.objects.ActivityWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.ActivityWrapper(), (anywheresoftware.b4a.BALayout)(_main.getObject())),__c.File.getDirRootExternal(),"",__c.True,__c.True,"Ok");
                                                                                                                                                                                                            ^
  required: BALayout
  found:    Class<CAP#1>
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object from capture of ?
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
You should pass the Activity object to Initialize. You will need to pass it to the class and store it in a global variable.

thanks thats what I did,
can you explain why I cant pass the activity as a param to the sub ?
 
Upvote 0
Top