1

I am new to android and I have a question I tried to launch an activity from an application (say App B) from another application (say App A) using this code:

Intent i = new Intent();
i.setComponent(new ComponentName("com.me.b","com.me.b.MainActivity"));
startActivity(i);

This is working fine but my question is : Why can't I call another activity from B except for its launcher?? Is ther any other way to launch B's other activities from A ?? Thanks in advance ...

1 Answers1

1

You can start any activity that is exported. For an activity, that usually means that it has an <intent-filter> that describes what the activity is expecting, and you should use an Intent that matches the filter.

You cannot start an activity that is not exported. Those are internal to the app. Frequently, it would not make sense to start them anyway, as those activities will have expected the user to have visited other activities first, and so not everything will necessarily be set up properly.

This pattern is fairly common:

  • You cannot necessarily run some command that opens a Windows program to an arbitrary dialog, even though the program itself can display that dialog when appropriate

  • You cannot necessarily use a URL in a Web browser to get to some internal page within a Web app, particularly those that require authentication, even though logged-in users can navigate to that URL

  • And so on

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491