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();
}
}
};
}
sp+几秒跳转
最新推荐文章于 2022-04-11 08:33:26 发布