Android: How To Know If User Is Still Touching Screen From Last Activity
I've an activity with an imageView, when user touches it, I open another activity with another imageView in the same place as the previous one, question is, I need to know if the u
Solution 1:
You'll need to store the touch event status in a global variable, that can be accessed between both activities.
With that, you'll need a separate Application-context class, like so:
import android.app.Application;
publicclassGlobalVarsextendsApplication {
publicstaticBooleanmouseDown=false;
}
The variable can be accessed like so:
finalGlobalVarsglobs= (GlobalVars)context.getApplicationContext();
globs.mouseDown = true;
So with that in mind, this should be what your onTouchListener might look like:
view.setOnTouchListener(newView.OnTouchListener() {
@OverridepublicbooleanonTouch(View v,MotionEvent event) {
finalGlobalVarsglobs= (GlobalVars)context.getApplicationContext();
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
globs.mouseDown = true;
break;
case MotionEvent.ACTION_UP:
globs.mouseDown = false;
break;
}
returntrue;
}
});
Hope this helps
Post a Comment for "Android: How To Know If User Is Still Touching Screen From Last Activity"