제목그대로 로그인 화면을 구현하고있습니다... Restful 과 파싱은 로그로 제대로 확인을 하였는데...
문제는 실패할때와 성공할때의 동작이 제대로 작동하지 않습니다 ㅠ ㅠ..... 코드는 이렇습니다.. URL은 대강 가려놨습니다.
도와주십시오 T.T
@Click({R.id.join, R.id.login, R.id.forget})
void click(View v){
switch (v.getId()) {
case R.id.join:
startActivity(new Intent(getApplicationContext(), JoinFormActivity_.class));
break;
case R.id.login:
new AttemptLogin().execute();
break;
case R.id.forget:
startActivity(new Intent(getApplicationContext(), ForgetUserActivity_.class));
break;
}
}
class AttemptLogin extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
boolean failure = false;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
long delayInMillis = 4000;
Timer timer = new Timer();
timer.schedule(new TimerTask() {
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
account = new Account();
String userId = id.getText().toString();
String userPw = pw.getText().toString();
jin.login(userId, userPw);
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("id", userId));
params.add(new BasicNameValuePair("pw", userPw));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
Intent i = new Intent(MainActivity.this, ControlActivity_.class);
finish();
// 데이터를저장합니다. (ID, Password)
SharedPreferences prefs = getSharedPreferences("PrefName", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("userId", userId);
editor.putString("userPw", userPw);
editor.commit();
startActivity(i);
return json.getString(TAG_MESSAGE);
}else{
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (file_url != null){
Toast.makeText(MainActivity.this, file_url, Toast.LENGTH_LONG).show();
}
}
}
}