3秒跳转(第一次显示第二次直接跳转)

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    Handler handler=new Handler(){
        @Override
        public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
            if(msg.what==0){
                Intent intent=new Intent(MainActivity.this, Main2Activity.class);
                startActivity(intent);

            }
            edit = sp.edit();
            return super.sendMessageAtTime(msg, uptimeMillis);
        }
    };
    private TextView tv;
    private SharedPreferences sp;
    int i=3;
    private SharedPreferences.Editor edit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        sp = getPreferences(MODE_PRIVATE);
        tv = (TextView) findViewById(R.id.tv);
        boolean b=sp.getBoolean("ss",false);
        if(b){
            Intent intent=new Intent(MainActivity.this, Main2Activity.class);
            startActivity(intent);
        }else{
            new Thread(){
                @Override
                public void run() {
                    while (true){
                        i--;
                        if(i==0){
                            Message msg = Message.obtain();
                            msg.what=i;
                            handler.sendMessage(msg);
                            edit.putBoolean("ss",true);
                            edit.commit();

                            break;
                        }
                        try {
                            sleep(1000);
                           
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                    }
                }

            }.start();
        }
    }
}
发布了8 篇原创文章 · 获赞 0 · 访问量 2347
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览