Reputation: 211
I need help on following:
When I touch on my mainActivity, it should handle onTouch event and start new activity which is a dialog activity. I am not able to do it. Can anyone suggest anything ?
I add android:theme="@android:style/Theme.Dialog"
.
If I design simple Dialog activity then it works fine but if I am trying to open it on touch event then it's not working.
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN) {
Intent loginIntent = new Intent(this, Login.class);
startActivity(loginIntent);
return true;
}
return true;
}
Upvotes: 1
Views: 1707
Reputation: 3427
you have to pass the context to your intent.and you have just wrote "this".and you are in Listener so it passes the Listener not the context of your activity.so you need to write YourActivity.this there. so replace this line
Intent loginIntent = new Intent(this, Login.class);
with this one
Intent loginIntent = new Intent(YourActivity.this, Login.class);
and you are done.hope this helps.
Upvotes: 2