Android Question Compile to Library issues - Passing data, and manifest declarations

thedesolatesoul

Expert
Licensed User
Longtime User
So far I have used Compile To Lib with great success in making my apps more compact and sharing code easier.
However there are a couple of things/concepts I struggle with.

So my main app has a service called MyService.
The compiled lib has MyClass and MyActivity. Only MyClass will call MyActivity.
So MyService instantiates MyClass. And calls a sub to start MyActivity.
Now basically MyActivity cannot see any of the process_globals from the main app, atleast not at compile time of the library. Can it see or access them at runtime?
HotShoe figured one way of doing that would be to use a code module, and use it to assign process_globals in the library, but you would need them defined in advance.
Instead I was using CallSubDelayed from MyClass to pass the class itself to MyActivity, but it would not show since there were no visible activities in the app. Eventually I got it to show using StartActivity after CallSubDelayed.
Is there an easier way to pass data to/from Activities compiled in libaries?

My second question is regarding manifest.
So I declare a theme to be Holo.Light in the manifest project for MyActivity. Once compiled to library, and the activity is launched, it uses the default theme.
But if I put this line in the manifest of the main app with MyService now, it does not compile saying MyActivity is not declared.
So how do I change the theme of this activity?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Now basically MyActivity cannot see any of the process_globals from the main app, atleast not at compile time of the library. Can it see or access them at runtime?
No. Library code cannot directly access code out of the library.

The main code can access MyActivity process global variables.

Instead I was using CallSubDelayed from MyClass to pass the class itself to MyActivity, but it would not show since there were no visible activities in the app. Eventually I got it to show using StartActivity after CallSubDelayed.
This is not related to libraries. CallSubDelayed doesn't start the target activity if the app is in the background (this is by design to avoid "popping" an activity).

Add a service to your library. You can then call it with CallSubDelayed even if the app is in the background.

About the second question. You should use the the library package name together with the activity name instead of just the activity name.
 
Upvote 0
Top