I created an AAR library on android and imported it into another project
When I try to execute something from this library, it gives an error saying that Room was not started, I start Room in my Application (),
which leads me to think that the Application () of the AAR library is not being called
How do I get this Application () to start?
There isn't any application class in the android-library that triggered automatically. You should expose an entry point in your library in order to receive the context and init everything you need from there (for example the Room DB).
Another way (maybe a little bit more complicated) is to create a provider and attach it in the application's lifecycle. Here is an example.
Related
I am working on an Cordova Android app. As part of the app, I wrote some Java classes to create a service using WorkManager to poll our server and send a notification to the client on certain events.
Right now the code is invoked through MainActivity.java, where I create the worker, and all of the classes sit in the Java folder under the Android Platform directory. My understanding is that this isn't ideal since my code will get dropped every time we want to reset the platform.
What is the right way to add this code to a project and is there a tutorial that I can follow? Should it all be a plugin?
Thank you in advance.
You should definitely refactor your code into a plugin. Check out the doc here
You can make your plugin for Android only as well.
I would recommend too, to clone a very simple plugin and check out the code.
I'm a bit of a newbie to all this.. but I can't seem to find any specific instructions for my scenario
I have built a simple endpoint api, using a maven project via eclipse.
I have built an android app, and just want to add a little test in it to use the simple api.
(sidenote: i have also built an app engine web app which will later also [i hope] make use of the same endpoint api, so both the web app and the android app make use of the same library / code)
anyway, I'm stumbling on a couple steps.
I can't seem to use the eclipse 'google -> generate cloud endpoint client library' option, since it's a maven project.
So i found on the google site, instructions to use the endpoints.cmd commandline to generate the library.
I successfully did this apparently (it created a zip file rather then just a jar)
here is where i am confused what to do next.. or if i missed something.
I have tried adding the jar within the zip as a library in the build path for my android app.
When I do that, I see that the Builder member doesn't seem to have been added.
Should I expect it to have been added by the library generation?
I can't seem to do anything in my android app code to use the library.
What am I missing / doing wrong?
I'm working on a server backend component for an app, and one goal is to log all the messages transmitted through the app (using MQTT). To do this, I wanted to use the app as a library of sorts so that I could use the objects defined within to parse the messages coming through, since none of the messages will be transmitted as standard types. I'm using IntelliJ for the Java development, and Android Studio for the Android development. Is this possible? I was previously able to import the code as a module, which let me use the types defined within, but when I went to build the project it tried to build the Android code as well and failed because IntelliJ hadn't set up Android dependencies. Should I try and set the Android SDK as a dependency in the app module, and then build? Or am I approaching this the wrong way? (if it's even possible) I understand that there are also Library projects which looks like a possible solution, it would just require re-factoring all the applicable code out to a different project and I was hoping that wouldn't be necessary.
Trying to import the entire Android app as a library into a different codebase probably isn't going to work; you don't want a non-Android app to have all that Android code linked in, and with resources and the whole environment it will be tough to get it to compile at all.
A better approach would be to take all of the code that needs to work cross-platform and distill it into a plain Java library that you can include in multiple contexts. On the Android side you could include it as a plain Java library project, or compile it to a jar and include the jar.
is there anyway to load a class from differen application ?
for example, I have two application and one of them has SomeExample class file. and I want to load it and use from another application.
I try to use, Class.forName. but this function throws "ClassNotFoundExpetion".
Is there anyway to load a class from differen application ?
No, sorry.
You can use startActivity(), startService(), and so on to launch components of another application, but each application's code remains separate.
While in most cases unadvisable (Android has many APIs to solve the common problems of inter-app communication without sharing code), it's possible by using PathClassLoader.
See also Android- Using DexClassLoader to load apk file.
I'm making a messaging app and I want to be able to extend it by using plugins.
The plugin might, for example, replace :) with a smiley image.
I've written some test code which uses intent filters to find the plugins, but I can't find a way to create an instance of the that plugin class.
Is it possible to do this, and if not, what would be the best approach/best alternative to this?
Thanks.
Because applications in android each run in their own VM, I don't think the classloader of your application will have access to the classes defined in the plugin. What you can do, however, is to pass the data between your main application and the plugin via Intents. If the plugin needs data from the main application, create a ContentProvider to make the data available.