简体   繁体   中英

Button finish activity after 2 press is WRONG: Android

I want the button to finish the activity. Why do I have to press it TWICE for it to finish, I do not want this. Note, I have to press the button twice before the activity ends, which I do not want.

MainActivity Class:

 private Runnable updateOkay= new Runnable() {
    public void run() {

    if (true) {
      Intent i = new Intent(this, WorkTimerNotification.class);
     startActivity(i); }

WorkTimerNotification class:

 public Button confirmButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_work_timer_notification);

    confirmButton = (Button) findViewById(R.id.confirmOK_button);
    confirmButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });
     }
    }

Solved by setting

android:launchMode = "singleInstance"

in AndroidManifest.xml file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM