簡易版log三秒跳轉

this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題欄

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息欄
sharedPreferences = getSharedPreferences("my3", Context.MODE_PRIVATE);
edit = sharedPreferences.edit();
flag = sharedPreferences.getBoolean("flag", true);
timer = new Timer(true);
timer.schedule(new TimerTask() {
    @Override
    public void run() {
        if (index>=3)
        {
            handler.sendEmptyMessage(1);
        }
        else
        {
            handler.sendEmptyMessage(0);
        }
    }
},1000,1000);
//handle
SharedPreferences sharedPreferences;
private SharedPreferences.Editor edit;
int index=0;
Handler handler=new Handler()
{
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        if (msg.what==0)
        {
            index++;
          //  Toast.makeText(MainActivity.this,""+index,Toast.LENGTH_SHORT).show();

        }
       else if (msg.what==1)
        {

            if (flag) {
                edit.putBoolean("flag", false);
                edit.commit();
                Intent intent = new Intent(MainActivity.this, DaohangActivity.class);
                startActivity(intent);
            } else {


                Intent intent = new Intent(MainActivity.this, HomeActivity.class);
                startActivity(intent);
            }
            timer.cancel();
        }
    }
};

發佈了53 篇原創文章 · 獲贊 8 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章