I have an Activity with a ListView (ItemsActivity) whose contents come from the JSON API. When I click one item in a ListView, it loads another action with details information (DetailActivity). The problem is that when I click the back button, the ItemsActivity reloads the ListView again.
I do not know where I can find additional information about this. I came from iOS where the previous screen does not restart every time.
I want to save ListView data between actions. I tested the call to the loadListItems () method from onResume (), but the same result.
Here is a short sample of my code. Any help and suggestions would be really appreciated.
public class ItemsActivity extends AppCompatActivity {
private ListView listItemView;
private Movie[] movies;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler);
listItemView = (ListView) findViewById(R.id.listItemView);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
loadListItems();
}
private void loadListItems(){
...
...
progressBar.setVisibility(INVISIBLE);
ListAdapter adapter = new ListAdapter(ItemsActivity.this, movies);
listItemView.setAdapter(adapter);
}
@Override
public void onClick(View v) {
Intent i = new Intent(this, DetailActivity.class);
i.putExtra("item_id", 1);
startActivity(i);
}
}
, ActivityOne ActivityTwo. ActivityOne , ActivityTwo "", ActivityOne onCreate().