Creating Android Libs That Export Activity

I followed the documentation on Android to create a library. Basically, I created a new project and then edited its properties to check the "Library" checkbox. Then I added a link to it in my executable project, using also "project properties" -> android-> Reference.

Everything looks fine, but I can’t figure out how to start the work that I included in the library project from the project being launched. For example, I run an action that is inside the project using

intent = Intent(this, ActivityClassName.class); 

But the following, which I did, was correct for activity in lib not working

 intent = Intent(com.example.libpack, ActivityClassName.class) 

I put exported actions in both manifest (lib and runnable)

I saw some tips on the Internet, but things are very unclear to me. Is this the right way to export and embed lib? Or should I use the Export option in the Eclipse File menu to export the JAR file from the library? If both options are possible, what would be better?

+4
source share
1 answer

You are doing it right, but the first argument to new Intent() is not the package the asset is in, but only the context. This will probably work if you use this again. If it still does not work, edit your question to include the error you received (check the LogCat and Console tabs).

When context is required and you are in Activity, it is better to use getApplicationContext () instead of this (see here ).

+4
source

Source: https://habr.com/ru/post/1342204/


All Articles