Android Studio: @Override "Annotations are not allowed here"
15,985
void onBackPressed ()
Called when the activity has detected the user's press of the back key. The default implementation simply finishes the current activity, but you can override this to do whatever you want.
In here you can't declare this method inside another method .
Only override it in that one Activity
@Override
public void onBackPressed()
{
super.onBackPressed();
}
FYI
@Override
public void onBackPressed() {
Intent intent = new Intent(IndividualAbsWorkout.this, IndividualAbsWorkout.class);
startActivity(intent);
}
Author by
Admin
Updated on June 04, 2022Comments
-
Admin about 2 years
I want to implement the ...
@Override public void onBackPressed() { }
However, I get an error message saying, "Annotations are not allowed here". I need this method to be implemented here. Is there an alternative?
public class supbreh extends Appbreh @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_intent_breh); if (myBundle != null) { String name = myBundle.getString("workout"); ShowDetails(name); } } private void ShowAbDetails(String mName) { if(mName.equals("abs1")){ @Override public void onBackPressed() { //"Not Allowed here" } }