I'd like to use activities that are not bundled with my app. How could I do that? Using intents or something? I am sure it must be simple.
UPDATE
The main problem is that I can't actually do this:
new Intent(this, SomeExternalActivity.class))
because I can't import the class (it's an external app). Something similar, using a string or something.
Thanks a lot!
UPDATE
This one doesn't work开发者_如何学编程 either:
new Intent(this, Class.forName("com.somepackage.SomeExternalActivity");
You can only start activities bundled with your app with this constructor:
Intent(Context packageContext, Class<?> cls)
You will need to use one of the following to access an external activity:
Intent(String action)
Intent(String action, Uri uri)
In your case you would use this intent:
new Intent("com.somepackage.SomeExternalActivity");
Also note that to access an activity in another app, that app needs to give access to it's activity (through AndroidManifest.xml)
Check the following for more explanation: http://developer.android.com/reference/android/content/Intent.html http://developer.android.com/guide/topics/manifest/manifest-intro.html http://developer.android.com/guide/topics/intents/intents-filters.html
This is a working example, for the RemoteDroid
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.joshsera", "com.joshsera.RemoteDroid");
startActivity(intent);
The activity you are calling should appear not only in the Manifest for its own package, but in the Manifest for the CALLING package, too.
精彩评论