testName testName - 1 year ago 91
Android Question

Getting Context of All Activities in Project Programmatically

I'm trying to create a function that globally changes a setting which is represented by a SharedPreference and can later be manually set for each activity. In the settings, I want to offer the user the ability to change the setting for every activity at once. Is there a way to get a list of Activity Contexts in a static function?

Answer Source

You can keep them all in the global preferences, just append the activity class name to the Preference key (like "activity_color_global", "activity_color_view"...), or use a different preference file name for each Activity.
By default set the value of all keys to 0 or null, which would mean to use the global preference (the one with the global name appended), and then user can change each one separately if they want.
To dynamically get a list of all included Activities, you can use the getPackageInfo function from the PackageManager class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download