简体   繁体   中英

When I press second time on the button , the app stops working

I am developing an app that consist of login-register app . In my login activity i have 2 buttons: LOGIN and REGISTER .The Register button is used to redirect you from login activity to register activity . The app works fine till I press once again . The app stops working.


final Button button = (Button) findViewById (R.id.button);
button.setOnClickListener (new View.OnClickListener(){
        @Override
        public void onClick (View v){
            Intent launchactivity = new Intent (Login.this,Register.class);
            startActivity (launchactivity);
        });

try to change from Login.This to getApplicationContext()

public void onClick (View v){
   Intent launchactivity = new Intent (getApplicationContext(),Register.class);
   startActivity (launchactivity);
});

删除您 login.this 并添加getApplicationContext()

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