Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve ActivityInfo for Activity Instance

I have an instance of an Activity in a helper class and I'm trying to obtain attributes from 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;
    }
}
like image 840
Jake Wharton Avatar asked Nov 25 '25 21:11

Jake Wharton


1 Answers

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

like image 50
smith324 Avatar answered Nov 28 '25 10:11

smith324



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!