D
D
Dauren S2017-01-06 13:25:30
Android
Dauren S, 2017-01-06 13:25:30

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);

or
navigateUpTo(new Intent(this, MainActivity.class));

How to make sure that when you click the created back button in the Toolbar, the download does not occur again. Do as if you press the back button on your device.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dauren S, 2017-01-06
@dauren101

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 question

Ask a Question

731 491 924 answers to any question