Tuesday, July 21, 2015

Launcher Activity without UI login / logout case

6:08 PM


Redirect user to different activities based on login logout stats or other intro activities on first run of the app. Launcher activity without UI helps achieve this with no UI glitches.

SET:  android:theme="@android:style/Theme.NoDisplay"
In your manifest file

        <activity
            android:name=".LauncherActivity"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoDisplay">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>


        </activity>

Use Activity Like this

package com.semicolondev.app;


import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

public class LauncherActivity extends Activity {

SharedPreferences preferences;


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

preferences = getSharedPreferences("MyApp", 0);


String firstRun = preferences.getString("first_run", "yes");
String isLogin = preferences.getString("login", "no");

if (firstRun.equals("no") && isLogin.equals("no")){

finish();
startActivity(new Intent(getApplicationContext(), LoginActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));

} else if ( firstRun.equals("no") && isLogin.equals("yes")){

finish();
startActivity(new Intent(getApplicationContext(), MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));

} else {

finish();
startActivity(new Intent(getApplicationContext(), IntroActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));

}



//setContentView(R.layout.activity_main);


}




}

Written by

We are passionate programmers. Enjoying the rich platforms of Semicolon Family of Programming languages we are proud to call ourselves Semicolon Developers.

0 comments:

Post a Comment

 

© 2013 Echo "Semicolon Developers"; Kathmandu. All rights resevered @ Semicolon Developers Network Pvt. Ltd.. Designed by Templateism

Back To Top