0
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar maintoolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(maintoolbar);
    Button  button =(Button)findViewById(R.id.login);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText e1=(EditText)findViewById(R.id.user);
            EditText e2=(EditText)findViewById(R.id.paswrd);
            String s1=e1.getText().toString();
            String s2=e2.getText().toString();
            MySync sync=new MySync();
            sync.execute(s1,s2);
        }
    });

}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

class MySync extends AsyncTask<String,Void,Integer>{
    ProgressDialog mProgressDialog;

    protected void onPreExecute(){
       //mProgressDialog = ProgressDialog.show(MainActivity.this, "Loading...", "Data is Loading...");
    }
    @Override
    protected Integer doInBackground(String... params) {
        int result =0;
        if(params[0].equals("Mayank") && params[1].equals("1234")) result=1;
        else result=2;

        return result;
    }

    protected void onPostExecute(Integer... result){
        if(result[0]== 1) startActivity(new Intent(MainActivity.this,Home.class));
       // mProgressDialog.dismiss();

    }
}

}

this doesnt lead me to home activity when username and password is correct that is mayank and 1234 why? sorry i am newbie to android this is for learning purpose only.when i click login button and enter correct information that is mayank and 1234 is doest lead me to new activity.

Mayank Singh
  • 75
  • 1
  • 1
  • 5
  • Are there any errors? exceptions? – Talha Mar 03 '16 at 19:53
  • 1
    You should learn Java's basics... you do not override base class method but create new method with different contract, which is not never called... – Selvin Mar 03 '16 at 20:02

1 Answers1

0

Try,

 protected void onPostExecute(Integer result){
        if(result== 1)
        startActivity(new Intent(MainActivity.this,Home.class));
       // mProgressDialog.dismiss();

    }

EDIT: Integer... result means it is expecting varags.You are returning "Integer" from doInBackground. I never used varags in return type of doInBackground (I use AsyncTasks alot), but I would use an array like protected Integer[] doInBackground(String... params) { if I were to return multiple values. See this post.

Community
  • 1
  • 1
Talha
  • 903
  • 8
  • 31