title: Save Widget State
body: <p>the document 
  <a href="http://developer.android.com/guide/topics/data/data-storage.html" rel="nofollow">http://developer.android.com/guide/topics/data/data-storage.html</a></p>
  
  <p>shows that there are multiple ways to save data, I need to do this in a widget and everytime I try to save i get errors...</p>
  
  <p>for instance</p>
  
  <pre><code>      SharedPreferences settings = getSharedPreferences("NAME", 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("silentMode", false);
  
        // Commit the edits!
        editor.commit();
  </code></pre>
  
  <p>Error</p>
  
  <pre><code>Description Resource    Path    Location    Type
  The method getSharedPreferences(String, int) is undefined for the type AWidget
  </code></pre>
  
  <p>another attempt:</p>
  
  <pre><code>     String FILENAME = "hello_file";
       String string = "hello world!";
  
       FileOutputStream fos = openFileOutput("Test.txt", Context.MODE_PRIVATE);
       fos.write(string.getBytes());
       fos.close();
  </code></pre>
  
  <p>with error</p>
  
  <pre><code>Description Resource    Path    Location    Type
  The method openFileOutput(String, int) is undefined for the type AWidget
  </code></pre>
  
  <p>whats the deal? I see no mention this does not work in a widget so why is it that these examples don't work for me?</p>
  
  <p>What is the preferred way to save this data?</p>