
Untitled
By: a guest on
May 22nd, 2012 | syntax:
None | size: 0.74 KB | hits: 15 | expires: Never
getFilesDir() in a subclass to View
public void save(){
try {
File myDir = new File(getFilesDir().getAbsolutePath());
FileWriter fw = new FileWriter(myDir + "/Test.txt");
fw.write(Integer.toString(score));
fw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
class Foo extends View{
public foo (Context c){
c.getFilesDir(); // or any method that belongs to context
}
}
class Main extends Activity{
@override
public void onCreate(){
super.onCreate();
Foo foo = new Foo(this); //this is a reference to the activity AND is also the context;
}
}
getContext().getFilesDir();