I have a package name and an activity name and开发者_如何学C I want to start a new class or activity using it. Is it possible to start the activity from code without declaring the same activity in the manifest file?
You can't start an activity if it isn't declared in the Manifest. All you might do is change the views programaticaly, but not the activity.
No, you can't do this (see the 2nd paragraph of the Activity 'Class Overview'). However...
If you want to do this to prevent people launching sub-activities directly, you can put logic in to detect the launching activity (via Activity.getCallingActivity / Activity.getCallingPackage) - you'll need to use StartActivityForResult to do this
You might be able to achieve what you want through a ClassLoader - more details on what you're doing (and why) would be useful.
If you're trying to launch an activity defined in a different package, then it only needs to be declared in the other package's manifest - you can then specify it with Intent.setClassName
Hope this helps,
Phil Lello
精彩评论