Showing logo 3 seconds before loading mainActivity [duplicate]

我与影子孤独终老i 提交于 2019-12-14 04:15:47

问题


I want to make a logo (an own activity)show in an own activity 3 seconds before the main activity loads, when starting my android app. Which is the simplest approach for doing this?

I have searched through this forum, I could only find one answered question around this topic, but unhappily it was unusefull for me.


回答1:


I think what you're referring is how to implement a Splash screen,

Create a new empty activity, I'll call it Splash for this example;

public class SplashScreen extends Activity {

    // Sets splash screen time in miliseconds
    private static int SPLASH_TIME = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        new Handler().postDelayed(new Runnable() {


            @Override
            public void run() {

                // run() method will be executed when 3 seconds have passed

                //Time to start MainActivity
                Intent intent = new Intent(Splash.this, MainActivity.class);
                startActivity(intent );

                finish();
            }
        }, SPLASH_TIME);
    }

}

Make sure you've set Splash activity as the launcher activity in your Manifest file :

 <activity
     android:name=".Splash"
     android:theme="@android:style/Theme.NoTitleBar">
       <intent-filter>

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

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

       </intent-filter>
</activity>


来源:https://stackoverflow.com/questions/39172166/showing-logo-3-seconds-before-loading-mainactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!