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();
            }
            
            
        }
  • 相关阅读:
    tars go版本源码分析
    goim源码阅读
    vue weixin源码解读
    避免加锁的骚操作
    git一些常用操作
    eclipse 的习惯配置
    ai资源站
    转载 github上的一些安全资源收集
    转载 一个统计代码行数的python脚本
    C语言开发工具
  • 原文地址:https://www.cnblogs.com/leshen/p/7363984.html
Copyright © 2011-2022 走看看