Commit 6341fe2d authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add extra to pass in if we want the default onBackPressed behavior for the...

Add extra to pass in if we want the default onBackPressed behavior for the Activity and want it to finish
parent b055ccb7
package chat.rocket.android.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
......@@ -13,9 +14,16 @@ import icepick.Icepick;
abstract class AbstractFragmentActivity extends RxAppCompatActivity {
public static final String EXTRA_FINISH_ON_BACK_PRESS = "EXTRA_FINISH_ON_BACK_PRESS";
private boolean finishOnBackPress;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent != null) {
finishOnBackPress = intent.getBooleanExtra(EXTRA_FINISH_ON_BACK_PRESS, false);
}
Icepick.restoreInstanceState(this, savedInstanceState);
}
......@@ -30,8 +38,13 @@ abstract class AbstractFragmentActivity extends RxAppCompatActivity {
@Override
public final void onBackPressed() {
if (!onBackPress()) {
onBackPressedNotHandled();
if (finishOnBackPress) {
super.onBackPressed();
finish();
} else {
if (!onBackPress()) {
onBackPressedNotHandled();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment