package com.example.android.onboarding; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import com.example.android.MainActivity; import com.example.android.R; import com.example.android.authentication.controller.AuthenticationActivity; import com.example.android.util.ResourceUtils; public class StartupActivity extends Activity { private static final AUTHENTICATION_REQUEST_CODE = 1000; @Override protected void onCreate(Bundle savedInstanceState) { if (isLoggedIn()) { Intent startupIntent = new Intent(this, MainActivity.class); startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(startupIntent); finish(); } else { Intent startupIntent = new Intent(this, AuthenticationActivity.class); startActivityForResult(startupIntent, AUTHENTICATION_REQUEST_CODE); } super.onCreate(savedInstanceState); } private boolean isLoggedIn() { // Check SharedPreferences or wherever you store login information return this.getSharedPreferences("my_app_preferences", Context.MODE_PRIVATE).getBoolean("loggedIn", false); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == AUTHENTICATION_REQUEST_CODE && resultCode == Activity.RESULT_OK) { Intent startupIntent = new Intent(this, MainActivity.class); startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(startupIntent); } finish(); } }