2

I have my application. It's working well. Now I developed a small addon which installs to system with hidden from launcher icon:

<activity android:name="GitHubSearch"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>

I'm trying to launch this Activity using this answer: Android: Starting An Activity For A Different Third Party App, but my app fails with Exception - Activity not found.

final Intent i = new Intent("android.intent.action.MAIN");
            i.setComponent(new ComponentName("com.example.me.module","com.example.me.module.MyActivity"));
            startActivity(i);

I checked 10 times the package names and activity names, that I'm passing to intent. Everything is fine.

Where is I'am going wrong?

Community
  • 1
  • 1
user1766287
  • 107
  • 10
  • 1
    Please post the code where you are trying to launch the other activity. – Code-Apprentice Jan 12 '13 at 23:42
  • So you want to call `GitHubSearch`? It seems you are trying to launch `MyActivity` instead. – A--C Jan 12 '13 at 23:53
  • If you want to start the GitHubSearch activity, why do you write MyActivity in the code for `setComponent`? – gosr Jan 12 '13 at 23:56
  • I provided here sample component name and activity name to hide my company. In the code the Activity name is correct. By the way, code working fine if I change in manifest category from default to launcher... – user1766287 Jan 12 '13 at 23:57
  • Have you tried adding `android:exported = "true"` to the xml for your Activity? – A--C Jan 12 '13 at 23:58

1 Answers1

2

It seems all you needed was

android:exported = "true"

To the activity node in your manifest xml.

By default, Android does not export Activities. Exporting an Activity means that it allows anything to start the Activity.

There are two ways to export - the above way, and setting a custom intent-filter.

If you want your new module to only communicate with your app, you can see this SO answer, however they note it is not recommended.

Community
  • 1
  • 1
A--C
  • 36,351
  • 10
  • 106
  • 92