我有一个android应用程序。在第一次运行时,第一个活动将打开并将在应用程序的存储中保存一个值。当我重新打开应用程序时,我想跳过第一个活动。我怎样才能做到这一点?Android-如何跳过第一个活动
当重新打开:
if(stogage_value == "enable"){
skip first activity;
}else{
first activity;
}
我有一个android应用程序。在第一次运行时,第一个活动将打开并将在应用程序的存储中保存一个值。当我重新打开应用程序时,我想跳过第一个活动。我怎样才能做到这一点?Android-如何跳过第一个活动
当重新打开:
if(stogage_value == "enable"){
skip first activity;
}else{
first activity;
}
节省首家推出布尔标志sharedpreference和
现在阅读活动启动前该值查布尔值
所以你的代码会是这样的
@Override
protected void onCreate(Bundle savedInstanceState) {
....
Boolean flag;
loadSavedPreferences();
Intent myIntent;
if(flag){
myIntent = new Intent(CurrentActivity.this, FirstActivity.class);
savePreferences()
}else{
myIntent = new Intent(CurrentActivity.this, NextActivity.class);
private void loadSavedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this);
flag = sharedPreferences.getBoolean("FirstLaunch", true);
}
private void savePreferences() {
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this);
Editor editor = sharedPreferences.edit();
editor.putBoolean("FirstLaunch", false);
editor.commit();
}
}
这里是slidenerd
后共享preference.And该值每一次检查第一次运行存储标志值,如果不是第一次运行时调用第二个活动。
Intent myIntent;
if(stogage_value == "enable"){
myIntent = new Intent(CurrentActivity.this, NextActivity.class);
}else{
myIntent = new Intent(CurrentActivity.this, FirstActivity.class);
}
CurrentActivity.this.startActivity(myIntent);
您需要使用共享偏好来维护计数器或标志。只需在第一次调用活动时将标志设置为true,然后在标志为true时调用另一个活动或执行其他操作。请参阅提供的答案here。
在OnCreate中,你可以在此实现way.You必须拯救“stogage_value”优先
boolean firstTime = ""; //get this value from preference
if(!firstTime){
Intent myIntent = new Intent(First.this, NextActivity.class);
firstTime = false;
// here save this in preference
}else{
setContentView(R.layout.main);
}
共享偏好视频教程,我只需运行新的活动,停止第一项活动
if(stogage_value == "enable"){
Intent i = new Intent(context, SecondActivity.class);
startActivity(i); //start second activity
finish(); //finish first activity
}else{
//do nothing
}
http://stackoverflow.com/q/16419627/1765530 – appukrb