Application Ignoring Boolean?
<p>I am currently trying to create a simple so that when a boolean is set to false, the applications' GoogleAPIClient would not connect.</p>

<p>However, the application, for some reason, goes through and connects anyway even after the boolean has set to false. How do I fix this kind of error?</p>

<p>The code snippet regarding this error is below:</p>

<pre><code>protected void onStart() {
    super.onStart();
    //Build resources if null
    if (mLocationClient == null) {
        buildLocationClient();
    }
    if (settings == null) {
        settings = getSharedPreferences(PREFS_NAME, 0);
    }

    Boolean RequestingLU = settings.getBoolean("RequestingLU", true);
    if (RequestingLU) {
        mLocationClient.connect();
        Toast.makeText(this, "You have connected", Toast.LENGTH_LONG).show();
    }
    else {
        mLocationClient.disconnect();
        Toast.makeText(this, "Don't connect please", Toast.LENGTH_LONG).show();
        StoppedMessage();
    }

}
</code></pre>

<p>This is the buildLocationClient():</p>

<pre><code>protected void buildLocationClient () {
    mLocationClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}
</code></pre>

<p>This is an AlertDialog from another activity editing the Setting</p>

<pre><code>            AlertDialog.Builder StopDialog = new AlertDialog.Builder(MainMenu.this);
            StopDialog.setTitle(R.string.Stop_Title);
            StopDialog.setMessage(R.string.Stop_Message);
            StopDialog.setPositiveButton(R.string.Stop_Button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    editor.putBoolean("RequestingLU", false);
                    editor.apply();
                    Toast.makeText(MainMenu.this, "You have stopped the app", Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                }
            });
</code></pre>

<p><strong>Some observations</strong></p>

<p>If RequestingLU is set to false, the "Don't Connect" toast comes up first, then "You have connected" comes up next.</p>

<p>If RequestingLU is set to true, the "Don't Connect" toast does not show up.</p>

<p>Swapping RequestingLU out for !RequestingLU does not work, still does the same effect.</p>

<p>I've tested the RequestLU setting, and it does return false if I change it so. The problem seems to be coming from the application not checking the boolean properly.</p>

<p>When the application is first started, the AlertDialog that is supposed to trigger when RequestingLU is false occurs, despite the default parameter stating that it is true by default.</p>

<p>Changing the default from true to false does no effect at all.</p>