안녕하세요 저는 지금 자동로그인을 구현 하려고 하는데 잘 되지 않아 질문을 드립니다.

 

GnbActivity에 CheckBox가 있고 그 CheckBox의 상태(Boolean)와 ID를 SharedPreferences에 저장해두었습니다.

 

그리고 LoginActivity에서 if문으로 나누어 자동로그인 CheckBox가 체크되어 있지 않으면

 

ID를 입력하고 로그인 버튼을 클릭해서 수동으로 로그인을 하고

 

자동로그인 CheckBox가 체크되어 있으면 LoginActivity에서 ID를 입력하고 Enter 버튼을 누를 필요 없이

 

바로 로그인하게 하려고 합니다.

 

그리고 LoginActivity가 제일 먼저 시작하는 Activity입니다.

 

지금 현재 코드를 아래와 같이 짰습니다.

 

public class LoginActivity extends BaseActivity implements OnClickListener {
 
 private static final String RESULT_CODE_SUCCESS = "0";
 public static final String USER_INFO = "user_info";
 public static final String PUT_TAB_LOCATION = "tab_location";
 public static final String LOGIN_PREFRENCE = "login_pref";
 
 private EditText enterprise_id;
 private EditText enterprise_pw;
 private Button enterBtn;
 private SharedPreferences settings;
 private ProgressDialog loadingDialog;
 
 private SharedPreferences autoLogin;
 
 private final Handler handler = new Handler() {
  public void handleMessage(Message msg){
   loadingDialog.dismiss();
   
   Intent intent = new Intent(LoginActivity.this, GnbActivity.class);
   intent.putExtra(PUT_TAB_LOCATION, 0);
   startActivity(intent);
   finish();
  }
 };
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.login_activity);
  
  // LoginActivity의 ID, PW 저장
  settings = getSharedPreferences(USER_INFO , Activity.MODE_PRIVATE);
  
  // 자동 로그인 체크 여부
  autoLogin = getSharedPreferences(LOGIN_PREFRENCE, Activity.MODE_PRIVATE);
  Boolean login = autoLogin.getBoolean("auto_login", false);
  
  if (login == false) {
   enterprise_id = (EditText)findViewById(R.id.entpid);
   enterprise_id.setOnClickListener(this);
   
   enterprise_pw = (EditText)findViewById(R.id.entppw);
   enterprise_pw.setOnClickListener(this);
   
   enterBtn = (Button)findViewById(R.id.id_enter);
   enterBtn.setOnClickListener(this);
   
   loadingDialog = new ProgressDialog(LoginActivity.this);
   
   // setClickAble(true);
  }
  else {
   // setClickAble(false);
   enterprise_id.setVisibility(View.GONE);
  }
 }
 
 public void setClickAble(boolean state) {
  enterprise_id.setClickable(false);
  enterprise_pw.setClickable(false);
  enterBtn.setClickable(false);
 }
 
 public void onClick(View view) {
//  loadingDialog.show();
  loadingDialog = ProgressDialog.show(this, "", "Loading...", true);
  switch (view.getId()) {
  case R.id.id_enter:
   Log.d("TEST", "Login click");
    
   EditText user_id = (EditText)findViewById(R.id.entpid);
   getDataManager().setUsername(user_id.toString());
   EditText passwd = (EditText)findViewById(R.id.entppw);
   final String userId = enterprise_id.getText().toString();
   final String userPw = enterprise_pw.getText().toString();
   // TODO: validation check
   
   new Thread(new Runnable() {
    public void run() {
     try {
      final String xml = LoginHelper.getInstance().doLogin(userId, userPw, getApplicationContext());
      
      SharedPreferences.Editor ed = settings.edit();
      ed.putString("user_id", userId);
      ed.putString("passwd", userPw);
      ed.commit();
      
      XMLDeserializer xmlDeserializer = new XMLDeserializer();
      xmlDeserializer.deserialize(xml, DataBean.class);
      DataBean data = (DataBean)xmlDeserializer.getParsingResult();     
      if (data.getResult().getCode().equals(RESULT_CODE_SUCCESS)) {
       getDataManager().setData(data);
      }
      handler.sendEmptyMessage(0);
     } catch (Exception e) {
      e.printStackTrace();
     }
    }
   }).run();
   
   break;
  default:
   break;
  }
 }
 
 private class LoadingThread extends Thread {
  private Handler handler;
  private final static int STATE_DONE = 0;
  private final static int STATE_RUNNING = 1;
  private int state;
  private int total;
  
  public LoadingThread(Handler handler) {
   this.handler = handler;
  }
  
  public void run() {
   state = STATE_RUNNING;
   total = 0;
   while (state == STATE_RUNNING)  {
    try {
     Thread.sleep(100);
    } catch (InterruptedException e ) {
    }
    
    Message msg = handler.obtainMessage();
    Bundle bundle = new Bundle();
    bundle.putInt("total", total);
    msg.setData(bundle);
    handler.sendMessage(msg);
    total++;
   }
  }
  
  public void setState(int state) {
   this.state = state;
  }
 }
}

 

else문에는 테스트를 위해 enter버튼이 안보이게 하는 코드를 넣었습니다.

 

저렇게 if문을 써서 하면 될 거라 생각 했는데 체크 박스가 체크 되어 있어도 enter버튼이 보입니다 ㅠㅠ

 

뭐가 잘못 된 것인지 지적 부탁드립니다 ㅠㅠ