Android XML internal storage

101 Views Asked by At

I am trying to save some data using XML in android to save into the devices internal storage.

I want to be sure the app is written by the open/closed and single responsibility -principle. (So i could easly switch between methods of storage)

-domain
|---db
|---|---appReader
|---|---|---AppReader.java
|---|---|---XMLAppReader.java
|---|---appWriter
|---|---|---AppWriter.java
|---|---|---XMLAppWriter.java   
|---DBFacade.java
|---DBFacadeImpl.java
-MainActivity.java

This is my current structure,...

The problem i am facing now, is that in every tutorial about android and xml they use the function openFileOutput(filename,Context.Mode_Append) I guess this is a function from Activity superclass ?

How would i have to initialise my FileOutputStream and still keep my open/closed and single responsibility principle intact ?

Should i pass an Activity instance to my XMLAppWriter constructor ? Doesn't this undermine the Single responsibility principle ?

1

There are 1 best solutions below

4
On BEST ANSWER

Instead of pass activity instance as parameter, you can use application's context method, which doesn't violate single responsibility principle.

getApplicationContext().openFileOutput(name, mode);