Reputation: 379
I am trying to go from one activity to another when clicking the 'Login' button, here is my code for button click-
public void onClick(View v) {
// TODO Auto-generated method stub
if(id.getText().toString().equals("ajay")&&pass.getText().toString().equals("sainy"))
{
Intent i = new Intent(MainActivity.this,adminhome.class);
MainActivity.this.startActivity(i);
}
else if(id.getText().toString().equals("aj")&&pass.getText().toString().equals("sa"))
{
Intent i = new Intent(MainActivity.this,userhome.class);
MainActivity.this.startActivity(i);
}
else
res.setText("Incorrect Credentials...Retry");
}
});
but when I enter correct credentials 'adminhome' or 'userhome' activity is not starting. The same 'MainActivity' is opening again. I think I have problem in following code -
Intent i = new Intent(MainActivity.this,adminhome.class);
MainActivity.this.startActivity(i);
or in,
Intent i = new Intent(MainActivity.this,userhome.class);
MainActivity.this.startActivity(i);
What is the problem? Please help, I am learning android.
Upvotes: 0
Views: 2491
Reputation: 221
Implement the View.OnClickListener interface and override the onClick method.
ImageView btnWatchVideo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search1);
ImageView btnSearch = (ImageView) findViewById(R.id.btnSearch);
btnSearch.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnSearch: {
Intent intent = new
Intent(Search.this,SearchFeedActivity.class);
startActivity(intent);
break;
}
}
Upvotes: 0
Reputation: 85
you can check and see if the new activity is put inside the manifest or not, as i did below
<activity
android:name="com.hossa.multitask.activity2"
android:label="@string/app_name" >
</activity>
Upvotes: 0
Reputation: 45942
The answer is in the comments, but anyway, when anyone of you encounters such behavior:
Upvotes: 1