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();
            }
            
            
        }
  • 相关阅读:
    删除当前目录下除了system目录的其他文件
    单例设计模式
    系统工程师
    字符串翻转
    教育
    得到b相对于a的路径
    一段处理事务的代码
    搭讪
    win 8 ,vs2011 编程环境下,动软生成器无法连接上 sql server 2008 r2
    从asp网站编程转行到asp.net网站编程的过程
  • 原文地址:https://www.cnblogs.com/leshen/p/7363984.html
Copyright © 2011-2022 走看看