我的问题是,如果用户无法登录数据库,我正在准备吐司,但即使用户成功登录我的数据库,吐司仍然出现 Login_layout
。
class BuatLogin extends AsyncTask<String, String , String> {
/**
* Sebelum memasuki menu buat progres dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Login_layout.this);
pDialog.setMessage("Login_layout Progress...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Konkesi
* */
protected String doInBackground(String... args) {
String usr = user.getText().toString();
String pwd = pass.getText().toString();
Log.d("1 "+usr, pwd);
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("usr", usr));
params.add(new BasicNameValuePair("pwd", pwd));
Log.d("2 "+usr, pwd);
Log.d(usr,url_create_login);
// getting JSON Object
// login url menerima POST method
JSONObject json = jsonParser.makeHttpRequest(url_create_login,
"POST", params);
// cek log untuk response
Log.d("Buat Respond", json.toString());
// check untuk sukses tag
try {
int sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
String nim=json.getString(TAG_NIM);
Log.d(TAG_NIM,nim);
// sukses login
Intent i = new Intent(getApplicationContext(), Mhs_main_layout.class);
i.putExtra(TAG_NIM, nim);
startActivity(i);
// tutup layar
finish();
} else if(sukses == 2) {
String nim=json.getString(TAG_NIM);
Log.d(TAG_NIM,nim);
Intent i = new Intent(getApplicationContext(), Admin_main_layout.class);
i.putExtra(TAG_NIM, nim);
startActivity(i);
// tutup layar ini
finish();
}else if(sukses == 3){
setResult(100);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}
protected void onPostExecute(String file_url) {
int resultCode = 100;
if (resultCode == 100) {
Toast.makeText(Login_layout.this, "Nip/Nim Atau Password TIdak Sesuai Silahkan Coba Lagi ", Toast.LENGTH_LONG).show();
}
pDialog.dismiss();
}
} }