zoukankan      html  css  js  c++  java
  • Android——倒计时跳转+sharedpreferences

    public class MainActivity extends Activity {
        // 3秒钟后,从图1跳转到图2(10)
        private Handler handler=new Handler(){
            public void handleMessage(android.os.Message msg) {
                int what=msg.what+1;
                if (what<=2) {
                    tv.setText("倒计时:"+(3-what)+"秒");
                    if (what==2) {
                        // 使用SharedPreferences保存状态,使应用第二次进入,进入图1,3秒后跳转到图2,不再播放动画(10)
                        SharedPreferences sp=getSharedPreferences("info", MODE_PRIVATE);
                        sp.edit().putBoolean("frist",true).commit();
                        startActivity(new Intent(MainActivity.this,Main2Activity.class));
                        finish();
                    }
                }
            };
        };
        private TextView tv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tv = (TextView) findViewById(R.id.textView1);
            
            new Thread(){
                
                public void run() {
                    
                    
                    //题目要求3秒
                    for (int i = 0; i <3; i++) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        //没一秒都要发送
                        handler.sendEmptyMessage(i);
                        
                    }
                };
            }.start();
            // 使用SharedPreferences保存状态,使应用第二次进入,进入图1,3秒后跳转到图2,不再播放动画(10)
            SharedPreferences spw=getSharedPreferences("info", MODE_PRIVATE);
            boolean boolean1 = spw.getBoolean("frist", false);
            if (boolean1) {
                startActivity(new Intent(MainActivity.this,Main2Activity.class));
                finish();
            }
            
            
        }
  • 相关阅读:
    msql 计算连续签到天数
    jetty启动常用命令
    nginx负载均衡, 配置地址带端口
    IDEA java 代码格式化统一
    Linux下安装Zookeeper
    nexus admin 从文件角度进行密码重置
    Monkey测试
    接口测试
    我的IT之路
    cookie 操作(转载)
  • 原文地址:https://www.cnblogs.com/leshen/p/7363984.html
Copyright © 2011-2022 走看看