title: Store value to Shared Preferences in a service class FirebaseInstanceIDService
body: <p>I'm trying to store type of user string in Shared Preferences in an Activity, but when i try to <code>getString</code> from Shared Preferences in a service class in this case myFirebaseInstanceIDService it keeps giving me a <code>Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference</code> error. </p>
  
  <p>Here is where i am putting the value</p>
  
  <pre><code>btNext.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              startActivity(new Intent(RegisterTutorActivity.this, ChooseSub.class));
              SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
              sharedPref.edit().putString("Type", "Tutor").apply();
              signUpTutor();
          }
      });
  </code></pre>
  
  <p>and in myFirebaseInstanceIDService</p>
  
  <pre><code>public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
  private FirebaseAuth mAuth = FirebaseAuth.getInstance();
  
  private String type;
  SharedPreferences sharedPref;
  
  @Override
  public void onTokenRefresh() {
      super.onTokenRefresh();
      if(mAuth.getCurrentUser() != null)
      {
  
          String refreshedToken = FirebaseInstanceId.getInstance().getToken();
          Log.d(TAG, "Refreshed token: " + refreshedToken);
          sendRegistrationToServer(refreshedToken);
      }
  }
  
  public void sendRegistrationToServer(String refreshedToken)
  {
      sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
      type = sharedPref.getString("Type", "");
      FirebaseDatabase.getInstance().getReference().child("Users").child(type).child(mAuth.getCurrentUser().getUid())
              .child("tokenID").setValue(refreshedToken);
  }
  }
  </code></pre>
  
  <p>I don't really now what i'm doing wrong with the Shared Preferences?</p>