Guy Cohen
Guy Cohen

Reputation: 769

android activity in jar library

I have copied an activity class from the internet : get user input

When I had the activity class inside the project, as a class file - it worked fine.

When I inserted the class +layout file into a different project (my dialogs.jar file) I could not start the activity.

The activity (TextEntryActivity) is under "com.xyz.dialogs" My project is under "com.xyz.thisproject"

First I got the "activity class not found" error: "AndroidRuntime(487): android.content.ActivityNotFoundException: Unable to find explicit activity class ..."

Then I read in an article that I should insert the startActivityForResult into a try/catch and I did.

The result is :

  1. Activity is not shown
  2. onActivityResult is fired without any action from the user

Notes:

  1. I put the activity in both manifests (first only in jar,then in my project, then both)
  2. I have another class (not activity!) in that JAR file and its working fine (a OK only dialog I build with dialog builder)

My questions are:

  1. Is it at all possible to put an activity in an external library ?
  2. Is it ok that that the layout file is in the jar (its only a textbox with two commands ok/cancel)
  3. Where should I declare the activity (which manifest or both?)
  4. How should I declare the activity (I saw samples with "ActivityName" and some other samples with ".ActivityName" where should I use what method...)

Thanks in advance Guy

Upvotes: 0

Views: 2231

Answers (1)

Stefan
Stefan

Reputation: 4705

I have at least a workaround: Make an Eclipse library project with your activity (there is an is-library property in the Android properties of an Android project) and make your second project use the library project. Here is more information on that topic: http://developer.android.com/guide/developing/projects/projects-eclipse.html

Then subclass your activity and declare the subclass in the manifest. This works around the package issue.

Upvotes: 2

Related Questions