Recently I was trying to use working back button on my one of the project, but whatever I was done previously was not working. It was a crash every time with error message -
I am newbie to Android, but I was done back activity few day back but after updating my Android Studios and APIs nothing was working. I was also uses inflated menu in my project, and debugger always stuck in onOptionsItemSelected(MenuItem item) method which I was used for option menu. I also tried many unsuccessful lines of code. Finally I got this solution for my problem -
I am newbie to Android, but I was done back activity few day back but after updating my Android Studios and APIs nothing was working. I was also uses inflated menu in my project, and debugger always stuck in onOptionsItemSelected(MenuItem item) method which I was used for option menu. I also tried many unsuccessful lines of code. Finally I got this solution for my problem -
1 . In onCreate(Bundle savedInstanceState) method use -
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
2 . Override methos in your activity class
@Overridepublic boolean onSupportNavigateUp() { onBackPressed(); return true; }3 . In onOptionsItemSelected(MenuItem item) method use -switch (item.getItemId()) { case android.R.id.home: Intent i = new Intent(this, Your_Parent_Activity.class); intent.addFlags(i.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); return true; }
No comments:
Post a Comment