[mobilesafe] 12_开启和关闭自动程序更新

Android 4.0

开启和关闭自动程序更新

延迟操作,利用handler.postDelayed()
public final boolean postDelayed(Runnable r, long delayMillis)
    {
        return sendMessageDelayed(getPostMessage(r), delayMillis);
    }
1、SplashActivity界面更新是否开启自动更新,决定是否从服务器上下更新版本
autoUpdate = this.getSharedPreferences("autoUpdateConfig"MODE_PRIVATE);
        boolean isAutoUpdate = autoUpdate.getBoolean("autoUpdate"true);// 默认为自动更新
        if (isAutoUpdate) {// 如果用户勾选了自动更新
            // 开启子线程从服务器上去获取新的版本信息
            new Thread(new CheckVersionTask()).start();
        } else {// 用户没有勾选自动更新
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    loadHomeUi();//进入主界面
                }
            }, 1000);
        }
2、 SettingActivity获取用户上次保存的自动更新的状态。 
// 2、获取一个SharedPreferences实例
        autoUpdate = this.getSharedPreferences("autoUpdateConfig"MODE_PRIVATE);
        boolean isAutoUpdate = autoUpdate.getBoolean("autoUpdate"true);// 默认为自动更新
        if (isAutoUpdate) {
            sv_setting_autoUpdate.setChecked(true);
        } else {
            sv_setting_autoUpdate.setChecked(false);
        }