I am new to Android programming and trying to learn the concepts, of course with the help from my fellow Stackoverflow user.
What i am trying to do: From the Login page, I am trying to fetch the login credentials from a json file located on a server. After parsing the json file and verifying the login credentials, i am starting a new intent to the next page of my app(Home).
Problem: I have successfully done all the networkings operations and parsing on a background thread using AsyncTask, as suggested by stackoverflow users. But, after verifying the login credentials, when i try to start a new intent inside the postExecute method of AsyncTask class, it gives me the following error. Please suggest what is wrong.
Error:
The constructor Intent(LoginActivity.RetreiveDataAsynctask, Class<HomeActivity>) is undefined
Error in line:
Intent intent = new Intent(this,HomeActivity.class);
code:
private class RetreiveDataAsynctask extends AsyncTask<String,Void,JSONObject> {
@Override
protected JSONObject doInBackground(String... loginURL) {
JSONObject obj = getJSONfromURL(loginURL[0]);
return obj;
}
@Override
protected void onPostExecute(JSONObject obj) {
//Do all ur UI related stuff as this will be executing in ui thread
super.onPostExecute(obj);
TextView loginStatus = (TextView) findViewById(R.id.login);
TextView userId = (TextView) findViewById(R.id.userId);
//if login successful, then go to the next page.
try {
loginStatus.setText(obj.getString("LOGIN"));
userId.setText(obj.getString("userId"));
AlertDialog.Builder adb = new AlertDialog.Builder(
LoginActivity.this);
adb.setTitle("Login Service");
adb.setPositiveButton("Ok", null);
if(obj.getString("LOGIN").equalsIgnoreCase("TRUE") && !obj.getString("userId").equalsIgnoreCase("")){
//call next page
adb.setMessage("Login Success...!!");
Intent intent = new Intent(this,HomeActivity.class); **//THIS LINE SHOWS ERROR**
startActivity(intent);
}else{//login unsuccessful
adb.setMessage("Login Failed...!!");
}
adb.show();
} catch (JSONException e) {
Log.e("log_tag", "JSONException "+e.toString());
}
}
@Override
protected void onPreExecute() {
TextView loginStatus = (TextView) findViewById(R.id.login);
TextView userId = (TextView) findViewById(R.id.userId);
loginStatus.setText("Not Fetched");
userId.setText("Not Fetched");
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
Looking for a solution. Thanks in advance.