Android - some code executes after the phone went to a different Activity
<p>I have a strange scenario here. </p>

<p>I have this code:</p>

<pre><code>// For checking if the person is logged in.
first_time_check();

setContentView(R.layout.main);

// ...next lines of code
</code></pre>

<p>and the first_time_check() function checks if the user is logged in for the first time.  If their user_id is not in the SharedPreferences, I redirect them to log in:</p>

<pre><code>public void first_time_check()
{   
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( ProblemioActivity.this);

    String user_id = prefs.getString( "user_id", null ); // First arg is name and second is if not found.
    String first_time_cookie = prefs.getString( "first_time_cookie" , null );               

    // About setting cookie.  Check for first time cookie
    if ( first_time_cookie == null )
    {
        // This user is a first-time visitor, 1) Create a cookie for them
        first_time_cookie = "1";

        // 2) Set it in the application session.
        prefs.edit().putString("first_time_cookie", first_time_cookie ).commit(); 

        // Make a remote call to the database to increment downloads number
        // AND send me an email that it was a new user.                 
    }        
    else
    {
        // If not first time, get their id.
        // If user_id is empty, make them an account.  
        // If id not empty, call the update login date and be done.         

        if ( user_id == null )
        {
            // User id is null so they must have logged out.                                
            Intent myIntent = new Intent(ProblemioActivity.this, LoginActivity.class);
            ProblemioActivity.this.startActivity(myIntent);
        }
        else
        {               
            // Make a remote call to the database to increment downloads number                                 
        }
    }

return;
}       
</code></pre>

<p>So after the code executes the </p>

<pre><code>            Intent myIntent = new Intent(ProblemioActivity.this, LoginActivity.class);
            ProblemioActivity.this.startActivity(myIntent);
</code></pre>

<p>it still executes below the original code that calls this functions.</p>

<p>Any idea how that can happen?</p>

<p>Thanks!!</p>
