Conditionally set first activity in Android

后端 未结 4 1465
北荒
北荒 2020-12-31 02:23

Currently we have a splash screen that is displayed in our app. However, if there is no data to be gathered or processed that is waiting, we\'d like to go straight into our

4条回答
  •  轮回少年
    2020-12-31 03:04

    Given that the launcher will start the activity you specify in your Manifest, it's not possible to set conditions on whether that activity will be started (or another).

    So you're left with the options as Richard Le Mesurier and dors suggest:

    1. Start the main Activity, then launch the Splash Activity if needed
    2. Start a gui-less Activity (no layout file), then decide which Activity should be presented to the user

    I'd prefer the second option, or if you're planning to introduce Fragments anyway, use them here:

    1. Use Fragments. Start your main activity, which has a Fragment placeholder. If you need to show Splash Screen, load the SplashScreenFragment in that activity, otherwise, load the Fragment that constitutes the first useful screen to the user.

    As an aside, the use of splash screens is discouraged; as a user, I'd prefer to see the main Activity with most of the static UI components loaded immediately, and some on-screen indication that something is loading/updating.

提交回复
热议问题