title: Android permission splash screen error API 19
body: <p>on my app I have implemented a control permission for Android 6 and 7.
  When app run show splash screen with message and after permission start the main activity. On Android 6 and 7 works fine but on Android 19 / 20 when i run app appear the message but the app remain blocked on splash screen and don't start main activity.
  this is my code:</p>
  
  <pre><code>public class splashscreen extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
  private GoogleApiClient googleApiClient;
  private Location myLocation;
  private static final int MY_PERMISSIONS_REQUEST_GET_ACCOUNTS = 1;
  private SparseIntArray mErrorString;
  
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.splash);
      mErrorString = new SparseIntArray();
  
  
  
  
  
  
  
      GoogleApiAvailability api = GoogleApiAvailability.getInstance();
      int code = api.isGooglePlayServicesAvailable(this);
      if (code != ConnectionResult.SUCCESS)
      {
          AlertDialog.Builder alert =  new AlertDialog.Builder(this);
          alert.setTitle("Attenzione");
          alert.setMessage("Google Play Services non installati o non aggiornati!");
          alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                  dialogInterface.dismiss();
                  finish();
              }
          });
          alert.show();
      }
  
      // Create an instance of GoogleAPIClient.
      if (googleApiClient == null) {
          googleApiClient = new GoogleApiClient.Builder(this)
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .addApi(LocationServices.API)
                  .build();
      }
  
  }
  
  
  
  
  
  
  protected void onStart() {
      googleApiClient.connect();
      super.onStart();
  }
  
  protected void onStop() {
      googleApiClient.disconnect();
      super.onStop();
  }
  
  
  // Permessi
  public void onPermissionsGranted(int requestCode) {
  
      Toast.makeText(getApplicationContext(), "Permission granted", Toast.LENGTH_SHORT).show();
  }
  
  public void requestAppPermissions(final String[]requestedPermissions, final int stringId, final int requestCode) {
      mErrorString.put(requestCode, stringId);
  
      int permissionCheck = PackageManager.PERMISSION_GRANTED;
      boolean showRequestPermissions = false;
      for(String permission: requestedPermissions) {
          permissionCheck = permissionCheck + ContextCompat.checkSelfPermission(this, permission);
          showRequestPermissions = showRequestPermissions || ActivityCompat.shouldShowRequestPermissionRationale(this, permission);
      }
  
      if (permissionCheck!=PackageManager.PERMISSION_GRANTED) {
          if(showRequestPermissions) {
              Snackbar.make(findViewById(android.R.id.content), stringId, Snackbar.LENGTH_INDEFINITE).setAction("GRANT", new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      ActivityCompat.requestPermissions(splashscreen.this, requestedPermissions, requestCode);
                  }
              }).show();
          } else {
  
              ActivityCompat.requestPermissions(this, requestedPermissions, requestCode);
          }
      } else {
          onPermissionsGranted(requestCode);
      }
  }
  
  @Override
  public void onRequestPermissionsResult(int requestCode,
                                         String permissions[], int[] grantResults) {
      switch (requestCode) {
  
          case 1: {
  
              if (grantResults.length &gt; 0
                      &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  //Toast.makeText(getApplicationContext(), "Permission granted", Toast.LENGTH_SHORT).show();
                  Intent i = new Intent(splashscreen.this, MainActivity.class); //start activity
                  splashscreen.this.startActivity(i);
              } else {
                  Intent i = new Intent();
                  i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                  i.setData(Uri.parse("package:" + getPackageName()));
                  i.addCategory(Intent.CATEGORY_DEFAULT);
                  i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                  i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                  startActivity(i);
                  /*Toast.makeText(getApplicationContext(), "Permission denied", Toast.LENGTH_SHORT).show();
                  Snackbar.make(findViewById(android.R.id.content), mErrorString.get(requestCode),
                          Snackbar.LENGTH_INDEFINITE).setAction("ENABLE", new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Intent i = new Intent();
                          i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                          i.setData(Uri.parse("package:" + getPackageName()));
                          i.addCategory(Intent.CATEGORY_DEFAULT);
                          i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                          i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                          i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                          startActivity(i);
                      }
                  }).show();*/
              }
              return;
          }
  
          // other 'case' lines to check for other
          // permissions this app might request
      }
  }
  
  
  @Override
  public void onConnected(Bundle connectionHint) {
      if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
          myLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
      }
      SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
  
      boolean isFirstStart = getPrefs.getBoolean("firstStart", true);
      if (isFirstStart) {
          android.app.AlertDialog alertDialog = new android.app.AlertDialog.Builder(splashscreen.this).create();
          alertDialog.setTitle(getResources().getString(R.string.titolo_intro_sms));
          alertDialog.setMessage(getResources().getString(R.string.intro_sms));
          alertDialog.setButton(android.app.AlertDialog.BUTTON_NEUTRAL, "OK",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          ActivityCompat.requestPermissions(splashscreen.this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
                          //Intent i = new Intent(splashscreen.this, MainActivity.class);
                          //startActivity(i);
  
                      }
                  });
          alertDialog.show();
  
          SharedPreferences.Editor e = getPrefs.edit();
          e.putBoolean("firstStart", false);
          e.apply();
      } else {
  
          startApp();
      }
  }
  
  private void startApp() {
  
      if(googleApiClient != null) {
          googleApiClient.disconnect();
      }
      startActivity(new Intent(splashscreen.this, MainActivity.class));
  
      finish();
  }
  
  @Override
  public void onConnectionSuspended(int i) {
      googleApiClient.connect();
  }
  
  @Override
  public void onConnectionFailed(ConnectionResult connectionResult) {
  }
  
  }
  </code></pre>