Reputation: 373
This is my Activity code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
overridePendingTransition(R.anim.trans_left_in, R.anim.trans_left_out);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
Log.d("Activity:", "SHOW");
}
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.trans_right_in, R.anim.trans_right_out);
Log.d("Activity:", "EXIT");
}
Whenever i enter this activity, "SHOW" appears in the log. But if i click the back button, the onBackPressed() doesn't get called and thus overridePendingTransition() neither.
I also set a breakpoint there and started the app in debug mode with the same result.
I'm using minSdkVersion 10 and targetSdkVersion 21.
What am i missing here?
Upvotes: 0
Views: 425
Reputation: 4867
You have to make a method which makes the actions you want and then call the onBackPressed(). Then you can call the method on the onBackPressed() and on your arrow button
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
goBack();
return true;
}
return super.onOptionsItemSelected(item);
}
private void goBack(){
super.onBackPressed();
overridePendingTransition(R.anim.trans_right_in, R.anim.trans_right_out);
Log.d("Activity:", "EXIT");
}
@Override
public void onBackPressed() {
goBack();
}
Upvotes: 1