Should put your file reading and writing into a utility class. I'd prefer doing it more vanilla style like the one I sent you, but yours can work if you pass along the context so you have access to openFileInput(..)