Wednesday, January 30, 2019
This is a useful tool, especial if you have a complex UI. the ability to go back to your previously opened Activity.
1. first you need to import the menuItem class on your opened Second Activity.
2. next add the following code under
3. now paste the follow code.
Its that simple, i hope this article was helpful.
1. first you need to import the menuItem class on your opened Second Activity.
import android.view.MenuItem;
2. next add the following code under
public class SecondActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_activity); //add back button getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
3. now paste the follow code.
@Overridepublic boolean onOptionsItemSelected(MenuItem item){ int id = item.getItemId(); if(id == android.R.id.home){ this.finish(); } return super.onOptionsItemSelected(item); }
Its that simple, i hope this article was helpful.