Back button for the base action bar activity.

This commit is contained in:
Anton Chekulaev 2020-09-17 15:11:05 +10:00
parent fc16622fcf
commit 037d10a7db

View File

@ -12,6 +12,7 @@ import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -42,6 +43,13 @@ public abstract class BaseActionBarActivity extends AppCompatActivity {
if (BaseActivity.isMenuWorkaroundRequired()) {
forceOverflowMenu();
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
}
super.onCreate(savedInstanceState);
}
@ -69,6 +77,14 @@ public abstract class BaseActionBarActivity extends AppCompatActivity {
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, new IntentFilter("unexpectedDeviceLinkRequestReceived"));
}
@Override
public boolean onSupportNavigateUp() {
if (super.onSupportNavigateUp()) return true;
onBackPressed();
return true;
}
@Override
protected void onDestroy() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);