public class FragmentThree extends Fragment {
private SharedPreferences.Editor editor;
private SharedPreferences preferences;
Handler handler = new Handler();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = View.inflate(getActivity(), R.layout.frag_three, null);
ImageView iv = view.findViewById(R.id.iv);
// 动画集合
AnimationSet animationSet = new AnimationSet(true);
// 透明度
AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0.2f);
animationSet.addAnimation(alphaAnimation);
// 缩放
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 2f, 1f, 0.5f);
animationSet.addAnimation(scaleAnimation);
// 旋转
RotateAnimation rotateAnimation = new RotateAnimation(0f, 90f, 0.5f, 0.5f);
animationSet.addAnimation(rotateAnimation);
// 设置动画时间
animationSet.setDuration(3000);
animationSet.setFillAfter(true);
iv.setAnimation(animationSet);
preferences = getActivity().getSharedPreferences("config", MODE_PRIVATE);
editor = preferences.edit();
// 记住页面
final Boolean flag = preferences.getBoolean("flag", false);
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (flag == false) {
editor.putBoolean("flag", true);
editor.commit();
Intent intent = new Intent(getActivity(), OtherActivity.class);
startActivity(intent);
getActivity().finish();
}
}
}, 4000);
return view;
}
}
/*****************************************************/
记住上面的页面 下次直接从第一个页面跳转
public class FragmentOne extends Fragment {
private SharedPreferences.Editor editor;
private SharedPreferences preferences;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// 加载布局
View view = View.inflate(getActivity(), R.layout.frag_one,null);
//
preferences = getActivity().getSharedPreferences("config",MODE_PRIVATE);
editor = preferences.edit();
final Boolean flag = preferences.getBoolean("flag",false);
if(flag){
Intent intent = new Intent(getActivity(), OtherActivity.class);
startActivity(intent);
getActivity().finish();
}
return view;
}
}
private SharedPreferences.Editor editor;
private SharedPreferences preferences;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// 加载布局
View view = View.inflate(getActivity(), R.layout.frag_one,null);
//
preferences = getActivity().getSharedPreferences("config",MODE_PRIVATE);
editor = preferences.edit();
final Boolean flag = preferences.getBoolean("flag",false);
if(flag){
Intent intent = new Intent(getActivity(), OtherActivity.class);
startActivity(intent);
getActivity().finish();
}
return view;
}
}