Android QQ交流群:813273942
具體做法,就是在本地儲存一個boolean值,如果進入首頁就修改boolean值
new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
if (SPUtils.getBoolean(getBaseContext(), "welcomeGuide", "isFirst")) {
goActivity(MainActivity.class);//首頁
} else {
goActivity(GuideActivity.class);//引導頁
SPUtils.putBoolean(getBaseContext(), "welcomeGuide", "isFirst", true);
}
finish();
return false;
}
}).sendEmptyMessageDelayed(0, 2000);//延遲2秒
這個是工具類SPUtils
public static boolean putBoolean(Context context, String fileName, String key, boolean value) {
SharedPreferences settings = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(key, value);
return editor.commit();
}
public static boolean getBoolean(Context context, String fileName, String key) {
return getBoolean(context, fileName, key, false);
}
public static boolean getBoolean(Context context, String fileName, String key, boolean defaultValue) {
SharedPreferences settings = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
return settings.getBoolean(key, defaultValue);
}