title: Checking if save preferences exist
body: <p>I wish to send the user to my Main Activicty the first time they log in. Here they enter a name which I save to an Intent and click a button to go to the second activity. I then show the Intent name on the second page.</p>
  
  <p>Every time the user logs in after this I wish to send them directly to the second activity.</p>
  
  <p>I tried this by sending the user to the second activity attempt to read a variable called loggedInOnceAlready , to see if it exists in SharedPreferences and if it is set to true. If it does not exist, create it and set it to false, then raise an intent to take the user to Main Activity. If it exists and is set to false, do nothing and continue with my Second Activity.</p>
  
  <p>After first login is complete in my second Activity, set it to true and store it back in my SharedPreferences.</p>
  
  <p>I feel this should work but am having issues implementing it</p>
  
  <p>Here is my Manifest firstly:</p>
  
  <pre><code>&lt;activity
          android:name=".SecondActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/title_activity_second" &gt;
  </code></pre>
  
  <p>My Second ACtivity:</p>
  
  <pre><code> public class SecondActivity extends AppCompatActivity {  
  
  String name;
  TextView etWelcome;
  String newName;
  
  SharedPreferences sharedPrefences;
  Boolean loggedInOnceAlready; 
  
    @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_second);
  
      sharedPrefences = PreferenceManager.getDefaultSharedPreferences(this);
      loadSavedPrefernce();
  
      Intent intent = getIntent();
      Bundle bundle = intent.getExtras();
      name = bundle.getString("name");
  
      etWelcome = (TextView)findViewById(R.id.tvWelcome);
      etWelcome.setText("Welcome " + name);
  
  }
  
  private void loadSavedPrefernce() {
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  
      if (loggedInOnceAlready = null){
          prefs.edit().putBoolean("loggedInOnceAlready", true).commit();
      }else {
          this.loggedInOnceAlready = false;
          savePreference(loggedInOnceAlready, "loggedInOnceAlready");
          Intent intent = new Intent(SecondActivity.this, MainActivity.class);
          startActivity(intent);
      }
  }
  
  private void savePreference(Boolean key, String value) {
      SharedPreferences.Editor editor = sharedPrefences.edit();
      editor.putBoolean("loggedInOnceAlready", false);
      editor.commit();
  }
  </code></pre>
  
  <p>And my Main ACtivity:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  SharedPreferences sharedPrefences;
  Boolean loggedInOnceAlready;
  
  String name;
  EditText etName;
  Button btnGo;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  
      btnGo.setOnClickListener(new View.OnClickListener() {
  
  
          @Override
          public void onClick(View v) {
              name = etName.getText().toString();
  
              prefs.edit().putBoolean("loggedInOnceAlready", true);
  
             // loggedInOnceAlready = true;
  
              Intent intent = new Intent(MainActivity.this, SecondActivity.class);
              intent.putExtra("name", name);
              startActivity(intent);
          }
      });
  
  }
  </code></pre>