安卓开发设置引导页面只显示一次

来源:互联网 发布:大数据研究生考试科目 编辑:程序博客网 时间:2024/05/18 03:32
public class HandlerActivity extends Activity {

    //是否是第一次使用
    private boolean isFirstUse;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_handler);
        
        SharedPreferences preferences = getSharedPreferences("isFirstUse",MODE_WORLD_READABLE);
        isFirstUse = preferences.getBoolean("isFirstUse", true);
        /**
         *如果用户不是第一次使用则直接调转到显示界面,否则调转到引导界面
         */
         if (isFirstUse) {
             startActivity(new Intent(HandlerActivity.this, MainActivity.class));
         } else {
             startActivity(new Intent(HandlerActivity.this, LoginActivity.class));
         }
         finish();
        //实例化Editor对象
         Editor editor = preferences.edit();
        //存入数据
        editor.putBoolean("isFirstUse", false);
        //提交修改
        editor.commit();
    }
}
阅读全文
0 0
原创粉丝点击