It's probably because you're using an OnTouchListener
, which triggers on press, move and release. Try using an OnClickListener
instead.
Finished activity automatically reopens
-
04-07-2022 - |
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?
La solution
Autres conseils
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);
}
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow