Start new activity and recognize, it is still being held + fullscreen

39 views Asked by At

I created two activities. If i hold an imageview i want to start the new activity but it doesn´t recognize in the new activity that it is still being held.

MainActivity

public class MainActivity extends AppCompatActivity {

ImageView imageView1;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageView1 = (ImageView) findViewById(R.id.imageView);

    imageView1.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if(event.getAction() == MotionEvent.ACTION_DOWN) {
                Intent i = new Intent( MainActivity.this, FullActivity.class);
                startActivity(i);
            }
            return false;
        }
    });
 }
}

Second Activity

public class FullActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_full);

    ImageView imageViewFull;

    imageViewFull = (ImageView) findViewById(R.id.imageViewFull);
    imageViewFull.setImageResource(R.mipmap.ic_launcher);

    imageViewFull.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(event.getAction()== MotionEvent.ACTION_UP){

                finish();
            }
            return true;
        }
    });
  }


}

Also my funtion to make the titlebar disappear doesn`t work.

2

There are 2 answers

0
Rak On

A touch event triggers by touching the screen, not by holding it down.

1
bharat7777 On

For start new activity you can use long press on image view and in the callback you can start new activity.

image_view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
          // start your activity...
            return false;
        }
    });

For make full screen you should use below these code.

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);