Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. getFilesDir() in a subclass to View
  2. public void save(){
  3.     try {
  4.         File myDir = new File(getFilesDir().getAbsolutePath());
  5.         FileWriter fw = new FileWriter(myDir + "/Test.txt");
  6.         fw.write(Integer.toString(score));
  7.         fw.close();
  8.  
  9.     } catch (FileNotFoundException e) {
  10.         e.printStackTrace();
  11.     } catch (IOException e) {
  12.         e.printStackTrace();
  13.     }
  14. }
  15.        
  16. class Foo extends View{
  17.    public foo (Context c){
  18.       c.getFilesDir(); // or any method that belongs to context
  19.    }
  20. }
  21.        
  22. class Main extends Activity{
  23.    @override
  24.    public void onCreate(){
  25.        super.onCreate();
  26.  
  27.  
  28.        Foo foo = new Foo(this); //this is a reference to the activity AND is also the context;
  29.    }
  30. }
  31.        
  32. getContext().getFilesDir();