Android judgment Interface

Source: Internet
Author: User

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();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.