I have 2 activities, LoginActivity and MainActivity. In the first activity i'm logging in the user and redirect him to the MainActivity. I have also have created in the MainActivity a sign-out button which calls this sign-out method:
private void signOut() {
    Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(new ResultCallback<Status>() {
        @Override
        public void onResult(Status status) {
            Intent intent = new Intent(MainActivity.this, LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    });
}
Every time the app starts, i check if the user in logged in. If it's logged in, the user remains in the MainActivity and if not, it is redirected to the LoginActivity.
The problem is, when the user is not logeed in, the app first of all starts the MainActivity and after that it starts the LoginActivity.
This is how my AndroidManifest looks like:
<activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
<activity android:name=".LoginActivity" />
How can i start the app, when the user is not logged in, without opening the MainActivity?
 
     
     
     
    