开发者

Retrieve ActivityInfo for Activity Instance

I have an instance of an Activity in a helper class and I'm trying to obtain attributes f开发者_如何学JAVArom its entry in the AndroidManifest.xml file.

I can get a list of all of the ActivityInfo instances but how do I to target the specific one for my application?

The activity instance is not in the same package as the helper class and not defined in the same manifest (helper class is a library included in the activity's application project).

What I have so far:

Activity activity = //the instance
String applicationPackage = activity.getApplicationInfo().packageName;
PackageInfo info = activity.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
for (ActivityInfo activityInfo : info.activities) {
    if (/* activityInfo applies to our activity instance */) {
        return activityInfo.someProperty;
    }
}


My understanding of your question: You need to get the information about a particular Activity within your Application.

Currently you are using getPackageInfo to obtain your package information from the package manager, but you don't need to do this if you only care about one Activity within the Application. You can use getActivityInfo instead, so long as you know the fully qualified name of the Activity and use a ComponentName, ex: com.example.myapp/com.example.myapp.myactivity

PackageManager Docs


If you want to retrieve the information of the current activity

ActivityInfo info = getPackageManager().getActivityInfo(getComponentName(), 0);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜