简体   繁体   中英

How to make the Android app load into logo then back to main activity?

I am new to App Development and I've been studying Kotlin for only a month now (1 hour everyday). I got the grasp of the functions but I still haven't gotten around using them for the purposes I have in mind.

Using Android Studio, I am trying to make the App load into a logo upon opening the app(Just like Facebook, Reddit), the logo is animated (which is not a problem for me). I have a couple of ways to achieve this but I wanna see what's the most efficient way to do it.

Create a new SplashActivity and change your starting activity in you manifest file like this:

<activity
    android:name=".SplashActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

then in your SplashActivity's OnCreate, start your MainActivity

startActivity(Intent(this, MainActivity::class.java))

You can read more about this here .

You can create one Activity let's say SplashActivity which will have your logo and animations you want. Then from that Activity you can start your MainActivity . If you need to process some data inside your SplashActivity you do that then you start MainActivity . Otherwise, if you don't have any data to process you can simply start MainActivity with some delay, like this:

 Handler().postDelayed({
            val i = Intent(this, MainActivity::class.java)
            startActivity(i)
        }, 5000)

This will start your MainActivity after 5000 milliseconds which is 5 seconds. Now try to write some code and if you run into a problem try to find a solution or ask again if you can't. There is a lot of tutorials on the Internet you can find on how to do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM