Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Android's system preferences without having any context

In an Android utility class, I want to get a system preference value in a class, but I don't have the context there, because the class that calls it doesn't have the context either. I've found that for Resources one can use the static Resources.getSystem() function. Is there any similar way for getting system preferences without context?

My class isn't an activity nor service. It's a utility class. Could give more info if needed.

like image 499
Mostafa Avatar asked Nov 29 '09 18:11

Mostafa


People also ask

How do I find application context?

To get a reference to the ApplicationContext in a Spring application, it can easily be achieved by implementing the ApplicationContextAware interface. Spring will automatically detect this interface and inject a reference to the ApplicationContext: view rawMyBeanImpl. java hosted by GitHub.

How many types of context are there in Android?

There are mainly two types of Context that are available in Android.

What is Android development context?

Definition. it's the context of current state of the application/object. It lets newly-created objects understand what has been going on. Typically, you call it to get information regarding another part of your program (activity and package/application).


1 Answers

You've got to send it a Context - don't try to run away from your responsibilities. :) Your utility class must be getting called by an Activity or Service at some level, and you're going to have pass that Context all the way down the line, through every method call. I know it's annoying, I've had to do similar things myself. Consider it an incentive to keep your code simple and to require as few method calls possible to get something accomplished.

like image 195
Eric Mill Avatar answered Oct 04 '22 00:10

Eric Mill