开发者

Open an activity without declaring it in the manifest file in ANDROID?

I want to open an activity without declaring it in an manifest file. I don't know if it is possible or not. What I actually want is to dynamically open an 开发者_开发问答activity from my program using intents. Can anyone help me if it is possible.


Not possible. Although I am unsure what you mean "dynamically open an activity".

See: http://developer.android.com/reference/android/app/Activity.html

Under Class Overview it states "To be of use with Context.startActivity(), all activity classes must have a corresponding declaration in their package's AndroidManifest.xml"

You can have an Activity in your package and not define it in the manifest, however you would not be able to start it successfully.


Your 'Dynamic' activity start is actually the normal way of starting an activity (as you have said in a comment to the answer of Matt M). Though you HAVE to add the Activities in manifest as Matt M said. In list view, clicking an activity will call a function that will start respective activity with startActivity() function.


I tried this very long, but since the Instrumentation class uses the IActivityTaskManager, which is a class of the internal API located at com.android.server.wm, that is not in the Activity classloader, I solved this by another method:

Using a subclass

I just made an Gist, with sample code.

GIST

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜