Pregunta

I have a problem in a very simple application.

I have a main activity, and on button click I open a second activity:

newEntryButton.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            Intent intent = new Intent(MainActivity.this, NewSpendingActivity.class);
            MainActivity.this.startActivity(intent);
            return true;
        }
    });

When I close this activity (for example by tapping the back button) or by calling finish() the view loads once again. It only closes if I tap the back button again. What may be the cause of this?

¿Fue útil?

Solución

It's probably because you're using an OnTouchListener, which triggers on press, move and release. Try using an OnClickListener instead.

Otros consejos

This should not give you problems:

newEntryButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            Intent activityChangeIntent = new Intent(MainActivity.this,NewSpendingActivity.class);
            MainActivity.this.startActivity(activityChangeIntent);

        }
    });
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top