Reputation: 1141
I have a button inside my activity layout,my Activity have extends and implement as MyActivity extends FragmentActivity implements LoaderCallbacks. on Click Listener of button I am calling another activity using startActivity but it not going on other activity even logs and try catch not getting any exception. Anyone can suggest me what can be the possible things I need to check to get away this issue ? Great thanks in advance. . .
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.categories);
Context context;
context = this;
imgViewLogin = (ImageView) findViewById(R.id.imageViewLogin);
imgViewLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(context,
NewActivity.class));
}
});
}
Upvotes: 0
Views: 1004
Reputation: 8947
Use this
startActivity(new Intent(getBaseContext(),
NewActivity.class));
Upvotes: 0
Reputation: 22493
try like this
startActivity(new Intent(MainActivity.this, NewActivity.class));
here MainActivity means your current activity where you place this code. instead of
startActivity(new Intent(context, NewActivity.class));
Upvotes: 1
Reputation: 13785
Use getApplicationContext() or activity.this
getApplicationContext() -
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.categories);
imgViewLogin = (ImageView) findViewById(R.id.imageViewLogin);
imgViewLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(),
NewActivity.class));
}
});
}
acivity.this -
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.categories);
imgViewLogin = (ImageView) findViewById(R.id.imageViewLogin);
imgViewLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(activity.this,
NewActivity.class));
}
});
}
Upvotes: 0