0

I have created two projects. The first one, extracts information of handset and shows on the screen. I have .apk file of this project (for example test.apk).

Then I created second project. This one has a button on the screen and I want when I click the button, first project runs (shows information of handset). I have added test.apk into this project by right clicking on root of project>Build Path>Configure Build Path>Add External JARs>test.apk

Then in the code, I called this by using intent. this is my code:

btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent("com.in.test.MainActivity"); 
                startActivity(intent);
            }
        });

however, when I run the application, according to logcat, I see following error: 11-18 10:09:28.933: E/AndroidRuntime(2237): Uncaught handler: thread main exiting due to uncaught exception 11-18 10:09:29.022: E/AndroidRuntime(2237): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.in.test.MainActivity } 11-18 10:09:29.022: E/AndroidRuntime(2237): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1484) . . .

What and where is my problem? Thanks

update: In the manifest file I added this line inside of application element:

<activity
            android:name="com.in.test.MainActivity" />

but the result is still the same. I'll try to follow your suggestion (using intent filter).

Hesam
  • 46,136
  • 63
  • 203
  • 340

2 Answers2

1

You can't do this from Eclipse. test.apk needs to be installed, and it needs to export the activity you need and have an intent filter for it. Something like:

 <intent-filter>
    <action android:name="com.infindo.test.MainActivity" />
    <category android:name="android.intent.category.DEFAULT" />
 </intent-filter>

If you have access to test.apk's source, modify it. If not, you can only use the activities/intents it exports.

Nikolay Elenkov
  • 51,084
  • 9
  • 81
  • 82
  • Thanks Nikolay. I think for using Intent filters, my first project should be installed on the handset first. after that I have to install wrapper project. then call to test project. But i don't want this. I want test project be a part of wrapper project. I don't have access to test codes and because of this i want to wrap it. and run it when I want. – Hesam Nov 18 '11 at 03:29
  • You need to convert it to a library project to include it in other projects. http://developer.android.com/guide/developing/projects/projects-eclipse.html#SettingUpLibraryProject – Nikolay Elenkov Nov 18 '11 at 03:39
0

To start an activity with an explicit intent like you are doing (by using the activity class in the constructor), the activity must be declared in the manifest for your app and must be complied into your app. You cannot use a separate apk file for that.

The way to do what you want is to declare an intent filter for the activity in test.apk and to launch it using an appropriate intent. See the guide topic Intents and Intent Filters and the documentation for the Intent class for more information about how to do this.

Ted Hopp
  • 222,293
  • 47
  • 371
  • 489
  • Thanks Ted. In my case I have access the codes of test project. But in future, I don't have access. How can I compile test project inside my application. is there any reference(s)? Thanks again. – Hesam Nov 18 '11 at 03:19
  • If all you want to do is launch one app from another, take a look at the answer in [this thread](http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent). Since you know details of the target application, you can skip some of the steps (i.e., looking up the package name). – Ted Hopp Nov 18 '11 at 04:21