使用Handler时

时间:2016-07-17 13:50:10

标签: android handler using

嗨everybady我尝试使用Handler但是我总结了问题 1.当我使用Handler时

Handler myHandler = new Handler() {
            @Override
            public void close() {

            }

            @Override
            public void flush() {

            }

            @Override
            public void publish(LogRecord record) {

            }
        }; 

但是我想要这种类型

Handler handler = new Handler();
handler.postDelayed(runnable3sec,3000);

如何解决我的问题  谢谢

3 个答案:

答案 0 :(得分:2)

只需更改Handler课程import

java.util.logging.Handler

android.os.Handler

答案 1 :(得分:0)

问题是您使用的导入,更改您的导入,例如导入android.os.Handler

答案 2 :(得分:0)

package com.softengine.mehmet.example2;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import java.util.Timer;
import java.util.concurrent.Delayed;
import java.util.logging.LogRecord;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ActionBar actionBar=getSupportActionBar();
        actionBar.hide();

        final Runnable runnable3sec = new Runnable() {
            @Override
            public void run() {
                nextActivity();
            }
        };
        Handler myHandler = new Handler();
        myHandler.postDelayed(runnable3sec,3000);


    }

    public void nextActivity(){
        Intent intent = new Intent(this,MainActivity.class);
        startActivity(intent);
    }
}

谢谢everybady:)