title: How to change activity while get 401 status code in Interceptor Android
body: <p>When I am getting <strong>401 status code</strong> in API then I have to <strong>open login activity</strong>. I don't want to put change activity logic in every API's onError method. I want a global method which used for all the API's. 
  So for that, I created one Interceptor</p>
  
  <pre><code>public class MyInterceptor extends BaseActivity implements Interceptor {
  
  @Override
  public Response intercept(Chain chain) throws IOException {
      Response response = chain.proceed(chain.request());
  
      if (response.code() == 401) {
  
          throw new RuntimeException(" Here you got 401 from API !");
      }
  
      return response;
  }
  }
  </code></pre>
  
  <p>Here I add this Interceptor</p>
  
  <pre><code>OkHttpClient.Builder builder=new OkHttpClient.Builder()
              .addNetworkInterceptor(new Interceptor() {
                  @Override
                  public okhttp3.Response intercept(Chain chain) throws IOException {
                      Request newRequest = chain.request().newBuilder()
                              .addHeader("Content-Type", "application/json")
                              .addHeader("User-Agent", "MyApp-Android-App")
                              .build();
                      return chain.proceed(newRequest);
                  }
              })
              .addNetworkInterceptor(new StethoInterceptor())
              .addNetworkInterceptor(new MyInterceptor())
              .addNetworkInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
  </code></pre>
  
  <p>Now, where should I add change activity call method. One more thing I am calling API using RxRetrofit. I want a <strong>global method for handling this 401 response</strong>. Can you please provide me any solution where should I put Activity change method call? </p>