Better back pressing logic

This commit is contained in:
topjohnwu 2018-08-30 04:19:08 -04:00
parent 64601baa76
commit adfffe6121

View File

@ -34,7 +34,7 @@ public class MainActivity extends BaseActivity
private final Handler mDrawerHandler = new Handler(); private final Handler mDrawerHandler = new Handler();
private int mDrawerItem; private int mDrawerItem;
private boolean fromShortcut = true; private static boolean fromShortcut = false;
@BindView(R.id.drawer_layout) DrawerLayout drawer; @BindView(R.id.drawer_layout) DrawerLayout drawer;
@BindView(R.id.toolbar) public Toolbar toolbar; @BindView(R.id.toolbar) public Toolbar toolbar;
@ -50,12 +50,7 @@ public class MainActivity extends BaseActivity
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
if (!mm.hasInit) { if (!mm.hasInit) {
Intent intent = new Intent(this, SplashActivity.class); startActivity(new Intent(this, SplashActivity.class));
String section = getIntent().getStringExtra(Const.Key.OPEN_SECTION);
if (section != null) {
intent.putExtra(Const.Key.OPEN_SECTION, section);
}
startActivity(intent);
finish(); finish();
} }
@ -83,8 +78,11 @@ public class MainActivity extends BaseActivity
drawer.addDrawerListener(toggle); drawer.addDrawerListener(toggle);
toggle.syncState(); toggle.syncState();
if (savedInstanceState == null) if (savedInstanceState == null) {
navigate(getIntent().getStringExtra(Const.Key.OPEN_SECTION)); String section = getIntent().getStringExtra(Const.Key.OPEN_SECTION);
fromShortcut = section != null;
navigate(section);
}
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
} }