Android/Java: How to make a static write method -


i have write method save few variables , use method throughout more 1 class. can need use in static places in classes won't work because save method cannot static.

here's method:

public void savelesson(int lessons2, int problem2, int mlessons2, int mproblem2, string checkaccuracy) {     string newline = system.getproperty("line.separator");     final string saved = new string(lessons + newline + problem + newline + mlessons + newline + mproblem + newline + dontcheckmaxstring());      fileoutputstream fout = null;      try {                fout = openfileoutput("lessonstore.properties", context.mode_private);     }     catch (filenotfoundexception e) {         e.printstacktrace();     }      outputstreamwriter osw = new outputstreamwriter(fout);     try {         osw.write(saved);         osw.flush();         osw.close();     }     catch (ioexception e) {         toast andeggs = toast.maketext(lessons.this, "error while writing...", toast.length_short);         andeggs.show();         e.printstacktrace();     } } 

so guess question is: how make method useable throughout classes; static or nonstatic methods?

you need context via method's parameters. can call context.openfileoutput.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -