I got an imageview which starts a new activity.
//Mainactivity
imageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// start your activity...
Intent i = new Intent( MainActivity.this, FullActivity.class);
startActivity(i);
return false;
}
});
I prefer to still hold my finger on the screen and if i realease my finger i get back to my MainActivity. I tried it with an ontouchlistener but it didnt recognize that i´m still holding the screen after the new activity start.
//Fullactivity
imageViewFull.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()== MotionEvent.ACTION_UP){
finish();
}
return true;
}
});
How to integrate that function?
I encountered the same problem and the only solution I found was to hold the button and peek at the previous activity for 3 seconds. Here's how i did it: Let's say that button1 from MainActivity sends you to the SecondActivity and by holding button2 in SecondActivity you can peek some seconds at MainActivity. So, in MainActivity, we assign to button1 a setOnClickListener:
In SecondActivity we assign
setOnClickListener
andsetOnLongClickListener
to button2:We pass the string "peek" for knowing in MainActivity if we want to peek or to fully return. Finally, we must implement onActivityResult in MainActivity:
Well, that's it! I hope this is usefull :D