Search code examples
androidmanifestandroid-7.1-nougat

Changing Main Activity in Manifest result to shortcuts doesn't work anymore


I try to add welcome tutorial for users that install application for the first time. That activity need to be declare as Main in Manifest (or I miss something?). But if I choose any other activity else than main one (which is actual app), app shortcuts (Android 7.1) doesn't work anymore. It's interesting however that shortcuts are still available at custom launchers (Apex, Nova). Any idea?


Solution

  • Thank you for the answers CommonWare! Your statements helps me to find answer. So, I want to start an app which shows Splash screen, then Welcome tutorial. Also, app need working shortcuts on main screen as well as only one launcher icon. So, first, I declare Splash screen as main in Manifest.xml:

            <activity
            android:name=".SplashActivity"
            android:noHistory="true"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data
                android:name="android.app.shortcuts"
                android:resource="@xml/shortcuts" />
        </activity>
    

    Then, Welcome (tutorial) activity:

            <activity
            android:name=".IntroActivity.WelcomeActivity"/>
    

    After that, in SplashActivity.class checking first launch:

    public static final String FIRST_APP_LAUNCH = "com.ips.test";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
            if (isFirstAppLaunch()) {
                setFirstAppLaunch(false);
                startActivity(new Intent(this, WelcomeActivity.class));
            } else {
                startActivity(new Intent(this, MainActivity.class));
            }
            finish();
        }
    
    private boolean isFirstAppLaunch() {
        SharedPreferences preferences = this.getPreferences(Context.MODE_PRIVATE);
        return preferences.getBoolean(FIRST_APP_LAUNCH, true);
    }
    
    private void setFirstAppLaunch(boolean value) {
        SharedPreferences preferences = this.getPreferences(Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(FIRST_APP_LAUNCH, value);
        editor.apply();
    }
    

    }

    Final result is as I wanted: app launch with Splash screen, then it runs Welcome tutorial. Next start will trigger Splash screen which will continue to main activity (app itself). When user click on shortcut in main screen it will get shortcuts, and in Launcher it will have just one application shortcut.