For the first time, go to the boot page. Otherwise, go to the boot page.
package edu.hpu.init;
import edu.hpu.logic.R;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
public class TellActivity extends Activity {boolean isFirstIn = false;
private static final int GO_HOME = 1000;
private static final int GO_GUIDE = 1001;
// Delay of 3 seconds
private static final long delayTime = 3000;
private static final String spName = "first_pref";
private Handler mHandler = new Handler() {@Override
public void handleMessage(Message msg) {switch (msg.what) {case GO_HOME:
goHome();
break;
case GO_GUIDE:
goGuide();
break;
}
super.handleMessage(msg);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
init();
}
private void init() {// Read the data required by SharedPreferences
// Use SharedPreferences to record the number of times the program is used
// Interface, MODE_PRIVATE specifies that the SharedPreferences data can only be read and written by this application
SharedPreferences preferences = getSharedPreferences(
spName, MODE_PRIVATE);
SharedPreferences.Editor editor;
editor = preferences.edit();
// Obtain the corresponding value. If this value is not found, it indicates that it has not been written. Use true as the default value.
isFirstIn = preferences.getBoolean("isFirstIn", true);// Determine the number of times the program is run. If it is the first run, it will jump to the boot interface. Otherwise, it will jump to the main interface.
if (!isFirstIn) {mHandler.sendEmptyMessageDelayed(GO_HOME, delayTime);
} else {// Use the postDelayed method of Handler to execute GuideActivity 3 seconds later
mHandler.sendEmptyMessageDelayed(GO_GUIDE, delayTime);
editor.putBoolean("isFirstIn", false);editor.commit();
}
}
private void goHome() {Intent intent = new Intent(this, StartActivity.class);
startActivity(intent);
this.finish();
}
private void goGuide() {Intent intent = new Intent(this, GuideActivity.class);
startActivity(intent);
this.finish();
}
}