title: Can't access SharedPreferences in class that extend Application
body: <p>I'm trying to code global method by extending the <code>Application</code> class.
  Specifically I'm trying to add 2 method to rapidly access one value that is stored in the <code>SharedPreferences</code>.
  Unfortunately I can't make the <code>SharedPreferences</code> work, here is the code:</p>
  
  <pre><code>package postfixcalculator.mattiarubini.com.postfixcalculator;
  
  import android.app.Application;
  import android.content.Context;
  import android.content.SharedPreferences;
  
  public class PostfixCalculatorExtendApplication extends Application {
  
      public void ChangePreference (boolean flag){
          //I'm updating the preference file based on the purchase
          SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
          SharedPreferences.Editor editor = sharedPref.edit();
          editor.putBoolean(getString(R.string.purchase_status), flag);
          editor.commit();
      }
  
      public boolean RetrievePreferences (){
          SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
          /*If the file doesn't exist, I create the file and I'm returned with a false value.
          * Because if the file was not created it's likely to be the first install.
          * If the user acquired the product on the store, it will be able to restore its purchase.*/
          boolean flagPurchase = sharedPref.getBoolean(getString(R.string.purchase_status), false);
          return flagPurchase;
      }
  }
  </code></pre>
  
  <p>I understand that <code>getActivity()</code> doesn't work in an <code>Activity</code> but in a <code>Fragment</code>, I just don't know what to do in this specific case.
  Usually in the <code>Activity</code>, to make <code>SharedPreferences</code> works, I just need to use the key word <code>this</code>.</p>
  
  <p>These are the errors I get: </p>
  
  <blockquote>
    <p>Cannot resolve method 'getActivity()'</p>
    
    <p>Cannot resolve method 'getPreferences(int)'</p>
  </blockquote>