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();
            }
            
            
        }
  • 相关阅读:
    Linux的JVM可以从SUN网站上下载
    实践是最好的老师
    SCAU 8624 多项式系数累加和
    SCAU 8617 阶乘数字和 (水题)
    SCAU 8614 素数
    SCAU 8619 公约公倍
    HDU ACM 1106 排序
    Uva 465 Overflow
    SCAU 8611 大牛之路I
    SCAU 9501 ACMer不得不知道的事儿
  • 原文地址:https://www.cnblogs.com/leshen/p/7363984.html
Copyright © 2011-2022 走看看