Answer the question
In order to leave comments, you need to log in
Back button on android?
There is an application with tabs and recycler view. Source in recycler view json. By clicking on the list item, you go to the DetailActivity.
In DetailActivity, when the back button is pressed on the device, in MainActivity everything is restored without loading. And when you click the created button back in the Toolbar, the tabs are loaded again.
Intent intent = new Intent(DetailActivity.this, MainActivity.class);
startActivity(intent);
navigateUpTo(new Intent(this, MainActivity.class));
Answer the question
In order to leave comments, you need to log in
In the Activity in which you want to return to the previous Activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar.setTitle("List Activity");
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
onBackPressed();// возврат на предыдущий activity
}
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question