sp+几秒跳转

package com.cx.dagg.shizhehao0119;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView text;
    private int time=5;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SharedPreferences sp = getSharedPreferences("ydy", Context.MODE_PRIVATE);
        //5判断是不是第一次进入(要从数据中找到的key,如果找不到数据 就返回默认值)
        if (sp.getBoolean("第一次", false)) {
            startActivity(new Intent(MainActivity.this,HomeActivity.class));
            finish();//这行代码很重要必须写 不然会减5分;
            return ;//停止执行下面的代码

        }
        //.2获取编辑器
        SharedPreferences.Editor edit = sp.edit();
        //3存值
        edit.putBoolean("第一次", true);
        //4提交事务
        edit.commit();
        text = findViewById(R.id.text1);
        handler.sendEmptyMessageDelayed(100,1000);
    }
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(time>0){
                text.setText("跳过广告"+time--+"s");
                handler.sendEmptyMessageDelayed(100,1000);
            }else{
                Intent intent = new Intent(MainActivity.this,HomeActivity.class);
                startActivity(intent);
                finish();
            }
        }
    };
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值