Reputation:
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"
}
}
Upvotes: 5
Views: 17152
Reputation: 75788
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);
}
Upvotes: 1
Reputation: 859
You can override onBackPressed as normal and call the method in ShowAbDetails() method like below.
@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")){
onBackPressed();
}
}
@Override
public void onBackPressed() {
// your logic here
}
Upvotes: 0