从快捷方式启动应用程序时如何显示启动屏幕

时间:2019-02-20 11:39:21

标签: android splash-screen

从快捷方式启动应用程序时,我无法找到如何显示启动屏幕。快捷方式是打开某些活动的直接路径,因此绕过了初始屏幕。任何想法如何在每个应用程序启动组合中包括启动画面?

我的启动实现:

public class SplashScreen extends AppCompatActivity {

    Context context = this;

    /** Duration of wait **/
    private final int SPLASH_DISPLAY_LENGTH = 2000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        new Handler().postDelayed( new Runnable(){
            @Override
            public void run() {
                /* Create an Intent that will start the Menu-Activity. */
                Intent goToMainActivity = new Intent(SplashScreen.this, MainActivity.class);
                goToMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(goToMainActivity);
                finish();
            }
        }, SPLASH_DISPLAY_LENGTH);
    }

}

清单:

<activity
            android:name=".SplashScreen"
            android:label="@string/app_name"
            android:noHistory="true"
            android:screenOrientation="portrait">
            <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/shortcut" />
        </activity>
        <activity
            android:name=".MainActivity"
            android:noHistory="true">
        </activity>

快捷方式:

<shortcut
        android:shortcutId="shortCutEnvironment"
        android:enabled="true"
        android:icon="@drawable/ic_action_temperature"
        android:shortcutShortLabel="@string/shortcut_environment"
        android:shortcutLongLabel="@string/shortcut_environment">

        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.app.myapp"
            android:targetClass="com.app.myapp.EnvironmnetScreen"
            />
        <category android:name="android.shortcut.conversation"/>

    </shortcut>

0 个答案:

没有答案