开发者

Loading activities dynamically

Is there any way to load an installed activity that isn开发者_开发百科't explicitly defined in my application manifest?


Sure. You could start the "gallery" to pick a photo like this:

myIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);  
startActivityForResult(myIntent, IMAGE_UPLOAD);

from the manual, we find you can have 2 types of intents to call:

Explicit Intents have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application.

Implicit Intents have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent.

You are looking for implicit intents I guess. This is explained a bit lower:

The intent resolution mechanism basically revolves around matching an Intent against all of the descriptions in the installed application packages. (Plus, in the case of broadcasts, any BroadcastReceiver objects explicitly registered with registerReceiver(BroadcastReceiver, IntentFilter).) More details on this can be found in the documentation on the IntentFilter class

(emph. mine). So you need either to know something to call it explicitly (like classname etc), or call the intent, and then you'd have to know the intent-filter.

I don't think there is a method to call something knowing only the package name: mind you, you can have an app with several packages, where not all have activities, let alone activities that can be run.


As Nanne said you can easily start an Activity via Intent.

Here is a list of system-provided intents: http://developer.android.com/guide/appendix/g-app-intents.html

And here is a list of intents provided by 3rd-party apps: http://www.openintents.org/en/registry


Is there any way to load an installed activity that isn't explicitly defined in my application manifest?

If you really meant to say:

Can my application create an Activity class at runtime...somehow...and launch it?

Then the answer is no.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜