I implemented Navigation Drawer in my app. It's just a sample app, auto-generated Navigation Drawer fragments and activities from Android studio. I'm starting an activity from a section list item like this:
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.pocetna);
break;
case 2:
mTitle = getString(R.string.oglasna_ploca);
break;
case 3:
mTitle = getString(R.string.e_novine);
break;
case 4:
mTitle = getString(R.string.portal);
break;
case 5:
mTitle = getString(R.string.raspored);
startActivity(new Intent(this, RasporedWebView.class));
break;
}
}
When I use the back button, could I get back to let's say case 1 or even MainActivity (closing navigation drawer), because when I call the activity, and go back it returns to a blank activitity (or w/e), and then I must click back button once more. I tried searching for solutions, but couldn't find any.
Thanks in advance.
Refer this Docs .
Then add the below code to do Back button in Activity
ActionBar actionBar;
actionBar=getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.