title: handleWindowVisibility: no activity for token android.os.BinderProxy
body: <p>I have a Login screen and upon success login, it finishes and shows another page that has information about the user.<br>
  I read about <a href="https://stackoverflow.com/questions/38298887/logout-dialog-error-token-android-os-binderproxy4276c0e8-is-not-valid-is-your">this post</a> and also <a href="https://stackoverflow.com/questions/7811993/error-binderproxy45d459c0-is-not-valid-is-your-activity-running">this post</a>.<br>
  I also read a lot about how we extend Application class but still it is not possible for me to run this code.<br>
  Below you can find my code and I will explain the error also.</p>
  
  <p>This is how I user Volley to call an AsyncTask:<br>
  The error is like <code>no activity for token android.os.BinderProxy</code> and it will come when I call <code>startActivity(intent);</code>.<br>
  I know this error is because the activity is killed and the AsyncTask after Volley response wants to use a killed context but I don't know how to fix it.</p>
  
  <pre class="lang-java prettyprint-override"><code>Util.request_function(
       activity,
       MainActivity.user_session,
       key_value,
       new VolleyCallback() {
            @Override
            public void onSuccess(JSONObject result, Context context) {
  
                   Activity activity = 
                   MyBaseActivity.myCustomApplication.getCurrentActivity();
                   Intent intent = new Intent(activity, SelfieCapture.class);
                   startActivity(intent);
                   finish();
            }
            @Override
            public void onError(String result) {
  
            }
  });
  </code></pre>
  
  <p>I have interfaces as below:<br>
  <strong>VolleyCallback.java:</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public interface VolleyCallback {
      void onSuccess(JSONObject result) throws JSONException;
      void onError(String result) throws Exception;
  }
  </code></pre>
  
  <p><strong>Util.java</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public static void request_function(Context context, CognitoUserSession cognitoUserSession, Map&lt;String, String&gt; key_value, final VolleyCallback callback) {
          JSONObject jsonBody = new JSONObject();
          CustomJSONObjectRequest postRequest = new CustomJSONObjectRequest(Request.Method.POST,
                  MainActivity.API_URL,
                  null,
                  response -&gt; {
                     JSONObject jsonObject = (JSONObject) response;
                     //SoMe Stuff//
                     callback.onSuccess(null);
               }, error -&gt; {
                     //Log Error//
               }){
                    @Override
                    public String getBodyContentType() {
                           return "application/json; charset=utf-8";
                    }
  
                    @Override
                    public Map&lt;String, String&gt; getHeaders() {
                    final Map&lt;String, String&gt; headers = new HashMap&lt;&gt;();
                    headers.put("Content-Type", "application/json");
                           return headers;
                    } 
  
                    @Override
                    public byte[] getBody() {
                           return jsonBody.toString().getBytes();
                    }
          };
       // Request added to the RequestQueue
       VolleyController.getInstance(context).addToRequestQueue(postRequest);
  
  </code></pre>
  
  <p><strong>MyCustomApplication.java</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public class MyCustomApplication extends Application {
  
      private Activity mCurrentActivity = null;
  
      public void onCreate() {
          super.onCreate();
  
      }
  
      public Activity getCurrentActivity() {
          return mCurrentActivity;
      }
  
      public void setCurrentActivity(Activity mCurrentActivity) {
          this.mCurrentActivity = mCurrentActivity;
      }
  }
  </code></pre>
  
  <p><strong>MyBaseActivity.java</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>public class MyBaseActivity extends Activity {
      public static MyCustomApplication myCustomApplication;
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          myCustomApplication = (MyCustomApplication)this.getApplicationContext();
      }
      protected void onResume() {
          super.onResume();
          myCustomApplication.setCurrentActivity(this);
      }
      protected void onPause() {
          clearReferences();
          super.onPause();
      }
      protected void onDestroy() {
          clearReferences();
          super.onDestroy();
      }
  
      private void clearReferences(){
          Activity currActivity = myCustomApplication.getCurrentActivity();
          if (this.equals(currActivity))
              myCustomApplication.setCurrentActivity(null);
      }
  }
  </code></pre>