淺析Android手機衛士關閉自動更新_Android

來源:互聯網
上載者:User

推薦閱讀:

淺析Android手機衛士自訂控制項的屬性

儲存資料的四種方式,網路,廣播提供者,SharedPreferences,資料庫

擷取SharedPreferences對象,通過getSharedPreferences()方法,參數:名稱,模式

例如config,MODE_PRIVATE

調用SharedPreferences對象的edit()方法,得到Editor對象

調用Editor對象的putBoolean()方法,放入布爾資料,參數:索引值對,”update” false

調用Editor對象的commit()方法,提交資料

查看/data/data/包名/shared_perfs/config.xml這個產生的xml檔案

使用命令列adb shell cd 到上面的目錄,使用cat命令查看檔案

調用SharedPreferences對象的getBoolean()方法,得到儲存的資料,參數:鍵,預設值

進行判斷,狀態設定為ture,設定常值內容

設定檢查下載部分

得到儲存的是否自動更新的狀態,判斷狀態

如果自動更新,調用檢測自動更新的代碼

如果不自動更新,延遲兩秒,自動跳轉到首頁

調用Handler對象的postDelayed()方法,參數:Runable對象,延遲的毫秒數

使用匿名內部類繼承Runable對象,重寫run()方法,方法裡面跳轉到首頁

升級進度的TextView部分,預設隱藏,android:visibility=”gone” gone是隱藏並空出位置

在下載過程中的回呼函數裡面,這一瞬間顯示出來

調用TextView對象的setVisibility(View.VISIBLE)

SettingActivity:

package com.qingguow.mobilesafe;import android.app.Activity;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import com.qingguow.mobilesafe.ui.SettingItemView;public class SettingActivity extends Activity {private SettingItemView siv_item;private SharedPreferences sp;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_setting);siv_item=(SettingItemView) findViewById(R.id.siv_item);sp=getSharedPreferences("config", MODE_PRIVATE);//根據儲存的資料設定狀態boolean update=sp.getBoolean("update", false);if(update){siv_item.setChecked(true);siv_item.setDesc("自動更新已經開啟");}else{siv_item.setChecked(false);siv_item.setDesc("自動更新已經關閉");}//自動更新的點擊事件siv_item.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {Editor editor=sp.edit();if(siv_item.isChecked()){//設定不選中siv_item.setChecked(false);siv_item.setDesc("自動更新已經關閉");editor.putBoolean("update", false);}else{//設定選中siv_item.setChecked(true);siv_item.setDesc("自動更新已經開啟");editor.putBoolean("update", true);}editor.commit();}});}}

以上內容是小編給大家介紹的Android手機衛士關閉自動更新的相關知識,希望對大家有所協助!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.