title: Volley Request only working in LoginActivity
body: <p>I have been trying to solve this problem for over 2 hours now.
  My POST requests all seem to work in my LoginActivity, but for some reason they don't in my MainActivity.</p>
  
  <p>My Webserver is handling requests fine.<br>
  The url is correct in my project, I just changed it here.</p>
  
  <p>Here is the MainActivity:</p>
  
  <pre><code>package com.my.app;
  
  
  import android.app.AlertDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.widget.TextView;
  
  import com.android.volley.Request;
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.StringRequest;
  import com.android.volley.toolbox.Volley;
  
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import okhttp3.MediaType;
  
  public class MainActivity extends AppCompatActivity {
  
      String serverResponse;
  
      Boolean apiKeyValid = false;
  
      // User Data
      String status, userID, username, klasse, email, fullname, description, pb, classRep, schoolRep, mod, lastLogin, firstVisit, bugsFound, apiKey, userSummary;
  
      public void validateApiKey(){
          SharedPreferences sp =
                  getSharedPreferences("Authentication",
                          Context.MODE_PRIVATE);
          if (sp.contains("apiKey")) {
              apiKey = sp.getString("apiKey", "false");
  
              RequestQueue MyRequestQueue = Volley.newRequestQueue(this);
              String url = "http://mydomain/api/v1/apiKeyValid";
              StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      try {
                          serverResponse = response;
                          JSONObject userData = new JSONObject(response);
  
                          status = userData.getString("status");
                          if (status.equals("valid")) {
                              apiKeyValid = true;
                          }
                      } catch (JSONException e) {
                          Log.e("App", "unexpected JSON exception", e);
                      }
                  }
              }, new Response.ErrorListener() { 
                  @Override
                  public void onErrorResponse(VolleyError error) {
  
                  }
              }) {
                  protected Map&lt;String, String&gt; getParams() {
                      Map&lt;String, String&gt; MyData = new HashMap&lt;String, String&gt;();
                      MyData.put("apiKey", apiKey);
                      return MyData;
                  }
              };
              MyRequestQueue.add(MyStringRequest);
          }
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          validateApiKey();
          if (apiKeyValid){
              TextView hello = (TextView) findViewById(R.id.hi);
              String msg = "Api Key is valid! :)\n" + "ApiKey: " + apiKey;
              hello.setText(msg);
          }
          else{
              Intent intent = new Intent(this, LoginActivity.class);
              startActivity(intent);
          }
      }
  
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
  
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
  
          int id = item.getItemId();
  
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p>If I should post anything else, just ask.
  Hopefully someone recognizes my problem, thank you! :)</p>