public class MainActivity extends BaseActivity {
private TextView textview;
private SharedPreferences sp;
@Override
protected int layoutRID() {
return R.layout.activity_main;
}
@Override
protected void initView() {
textview = findViewById(R.id.textview);
}
@Override
protected void initData() {
sp = getSharedPreferences("ydy", Context.MODE_PRIVATE);
if (sp.getBoolean("first", false)) {
startActivity(new Intent(MainActivity.this, SecondActivity.class));
finish();
return;
}
textview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sp.edit().putBoolean("first", true).commit();
startActivity(new Intent(MainActivity.this, SecondActivity.class));
handler.removeCallbacksAndMessages(null);
finish();
}
});
handler.sendEmptyMessageDelayed(0, 1000);
}
int time = 5;
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (time > 0) {
time--;
textview.setText(time + "S");
handler.sendEmptyMessageDelayed(0, 1000);
} else {
sp.edit().putBoolean("first", true).commit();
startActivity(new Intent(MainActivity.this, SecondActivity.class));
handler.removeCallbacksAndMessages(null);
finish();
}
}
};
}
引导页&五秒跳转
最新推荐文章于 2024-07-22 11:19:47 发布