Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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);

        }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top