I’ve followed the Android documentation to create a library. Basically, I’ve created a new project and, then, edited it’s properties to check the “is Library” box. Then I’ve added a reference to it at my runnable project, using also “project properties”->android->Reference.
Everything seems ok, but I can’t figure out how to, from the runnable project, start an activity I’ve put in the library project. For example, I start an activity that is inside the project using
intent = Intent(this, ActivityClassName.class);
But the following, which I tought was the correct for a activity in a lib, doesn’t work
intent = Intent(com.example.libpack, ActivityClassName.class)
I’ve put the exported activities in both manifests (lib and runnable)
I’ve seen some hints on web, but things are very obscure to me. This is the right way to export and embed an lib? Or should I use the Export option in Eclipse File menu to export a JAR file from the library? If both are possible, which would be better?
You’re doing right, but the first argument to
newIntent()is not the package the activity is in, it’s just the context. It will probably work if you use againthis. If it still doesn’t work, please edit your question to include the error you’re getting (check LogCat and Console tabs).When a context is required and you’re in an Activity, it’s better to use getApplicationContext() instead of
this(see here).