I've been working on developing a library for my company for the past couple months and have been annoyed by the fact that filestreams seem to need a context whenever I store or load data to the internal storage.
I have designed the library to work like this :
- A singleton class is made for providing and handling a keychain(containing app key and device id) and authinfo(user and password)
Whenever a request to call to a web service is made the calling class will attempt to get an instance of the singleton class and get the keychain and auth info through it like such :
SingletonClass.getInstance().getCredentials(Context ctx);
The result of this is that I need to constantly provide the context of the calling activity as most of my library revolves around calling an API with credentials and device id as parameters.
I am specifically referring to these lines :
....
FileOutputStream fos = ctx.openFileOutput(filename,
Context.MODE_PRIVATE);
fos.write(buf);
fos.close();
....
I am confused as to why the specific context of the activity calling is needed. Any help is greatly appreciated. Is there another way of solving this design issue ?