android 后退

android on back pressed

@Override
public void onBackPressed(){
    if (back_pressed + 2000 > System.currentTimeMillis()){
        Homepage1.super.onBackPressed();
    }
    else{
        Toast.makeText(getBaseContext(), "Press once again to exit", Toast.LENGTH_SHORT).show();
        back_pressed = System.currentTimeMillis();
    }
}

Error:(51, 42) error: ';' expected Error:Execution failed for task ':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details.

把这个方法放在里面 Activity class.

public class MyActivity extends AppCompatActivity {

    @Override
    public void onBackPressed() {
        if (back_pressed + 2000 > System.currentTimeMillis()){
                    Homepage1.super.onBackPressed();
                }
                else{
                    Toast.makeText(getBaseContext(), "Press once again to exit", Toast.LENGTH_SHORT).show();
                    back_pressed = System.currentTimeMillis();
                }
    }
}