布局文件
1,引导页
activity_guide.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GuideActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="引导页"
android:layout_centerInParent="true"
android:textSize="50sp"/>
</RelativeLayout>
2,首页
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="首页"
android:layout_centerInParent="true"
android:textSize="50sp"/>
</RelativeLayout>
java代码
GuideActivity
package com.example.a20191q;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class GuideActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guide);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(GuideActivity.this, MainActivity.class));
finish();
}
}, 3000);
}
}
MainActivity
package com.example.a20191q;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
public SharedPreferences preferences;
public SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
preferences = getSharedPreferences("data", MODE_PRIVATE);
editor = preferences.edit();
if(preferences.getBoolean("first",true)){
editor.putBoolean("first", false);
editor.apply();
startActivity(new Intent(MainActivity.this,GuideActivity.class) );
finish();
}
}
}