【问题标题】:Error in writing splashscreen code with timer使用计时器编写启动画面代码时出错
【发布时间】:2018-01-05 23:13:54
【问题描述】:

所以我正在 Android Studio 中编写一个应用程序,我是一个初学者。因此,在我的带有计时器的启动画面的代码中存在一个错误导致其他错误。我真的试图修复它,但我无法弄清楚。抱歉,如果这已经写在某个地方,我也是 stackoverflow 的新手,所以我并没有真正理解它。谢谢你的帮助。 这是错误图片链接->https://imgur.com/MdXs4up

这是代码

package com.example.shromid;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SplashScreen extends AppCompatActivity {
    private static int SPLASH_TIME_OUT=4000;

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

    new Handler().postDelayed(new Runnable(){
        @Override
        public void run() {
            Intent homeIntent=new Intent(SplashScreen.class,MainActivity.this);
            startActivity(homeIntent);
            finish();
        }
            }SPLASH_TIME_OUT);
            }
    }
}    

【问题讨论】:

    标签: java android android-studio splash-screen


    【解决方案1】:
    new Handler().postDelayed(new Runnable(){
        @Override
        public void run() {
            Intent homeIntent=new Intent(SplashScreen.class,MainActivity.this);
            startActivity(homeIntent);
            finish();
        }
    }, SPLASH_TIME_OUT); // See the comma?
    

    您缺少匿名 Runnable 的定义结尾和第二个参数(即处理程序延迟)之间的注释。

    【讨论】:

    • 谢谢,这就是解决方案,我用点代替逗号。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    相关资源
    最近更新 更多