@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.