2013-04-20 70 views

回答

6

要达到此目的,您可以使用SharedPreferences

打开此活动后,将首选项中的值保存为true。并在下次检查时如果它的值为false,则打开否则不打开。

在您打开活动之前,请检查它。

SharedPreferences sharedPref = getSharedPreferences("data",MODE_PRIVATE); 
int number = sharedPref.getInt("isOpened", 0); 
if(number == 0) { 
    //Open this activity and set this so that next it value is 1 then this conditin will be false. 
    SharedPreferences.Editor prefEditor = sharedPref.edit(); 
    prefEditor.putInt("isOpened",1); 
    prefEditor.commit(); 
} 
+1

+1很久以后.. – Pragnani 2013-04-20 16:23:19

0

为此,您必须检测应用程序的首次启动。

要做到这一点,你可以做一件事。

  1. 使用SharedPreference存储值first_launch,默认值为true。
  2. 启动应用程序后,检查该值是否为首次运行 a。如果first_lunch true显示欢迎页面并使其为假 b。如果first_lunch false然后只是开始你的主要活动
0

最简单的方法是存储在SharedPreferences东西。

public void onCreate(Bundle savedInstaceState){ 
    super.onCreate(savedInstaceState); 

    if(savedInstanceState == null){ 
     SharedPreferences sp = getSharedPreferences("settings", 0); 
     if(sp.getBoolean("old", false))){ 
      // start the real 1st Activity 
      startActivity(new Intent(this, com.example.Activity)); 
      finish(); 
     }else{ 
      sp.edit().putBoolean("old", true).commit(); 
     } 
    } 

    // add the use once screen stuff here 
} 
相关问题