Android 中設置隻是程序第一次運行才顯示的界面

程序安裝後第一次啟動:
啟動頁–>功能介紹頁–>系統主頁
以後啟動:
啟動頁–>系統主頁

所以在啟動頁中判斷一下就可以瞭
可以弄一個文件保存一個狀態,推薦用SharedPreferences。

1.可以定義一個變量來判斷程序是第幾次運行,如果是第一次則跳轉到引導的Activity,如果不是第一次則執行系統主頁。

判斷系統是第一次運行的代碼實現如下:

在Activity中添加代碼:

使用SharedPreferences來記錄程序的使用次數

一下是實現的代碼:

[java]
<SPAN style="FONT-SIZE: 18px"><STRONG>public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
         
        preferences = getSharedPreferences("count",MODE_WORLD_READABLE); 
        int count = preferences.getInt("count", 0);  
         
        //判斷程序與第幾次運行,如果是第一次運行則跳轉到引導頁面   
        if (count == 0) {  
        Intent intent = new Intent(); 
        intent.setClass(getApplicationContext(),LaunchGuideViewActivity.class);  
        startActivity(intent);  
        this.finish();  
        }  
        Editor editor = preferences.edit();  
        //存入數據    
        editor.putInt("count", ++count);  
        //提交修改    
        editor.commit();</STRONG></SPAN> 

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
  preferences = getSharedPreferences("count",MODE_WORLD_READABLE);
  int count = preferences.getInt("count", 0);
  
  //判斷程序與第幾次運行,如果是第一次運行則跳轉到引導頁面
  if (count == 0) {
  Intent intent = new Intent();
  intent.setClass(getApplicationContext(),LaunchGuideViewActivity.class);
  startActivity(intent);
  this.finish();
  }
  Editor editor = preferences.edit();
  //存入數據 
  editor.putInt("count", ++count);
  //提交修改 
  editor.commit();

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *