In my Android manifest, I am specifying a parentActivityName in order to utilise the back button displayed in the activity.
I find this however re-calls onCreate of the previous activity, in which I do several network calls and set up a recycler view widget.
This causes the screen to refresh entirely, I'd like to avoid this and deal with the recyclerview and what new content to display and delete to ensure the user flow is not jolted.
I currently set my application up in onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_container_list);
final SwipeRefreshLayout swiperefreshContainerListRecyclerView = (SwipeRefreshLayout) this.findViewById(R.id.swiperefresh_container_list_recyclerview);
swiperefreshContainerListRecyclerView.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshContainerList();
}
}
);
// Get a handle on our RecyclerView for interactin and setup
containerListRecyclerView = (RecyclerView) findViewById(R.id.container_list_recyclerview);
// Grab a new LayoutManager
containerListLayoutManager = new LinearLayoutManager(this);
// Grab a new adapter
List<ContainerModel> containers = new ArrayList<>();
containerListRecyclerAdapter = new ContainerListRecyclerViewAdapter(containers, this);
// Better performance as the size of our RecyclerView does not change
containerListRecyclerView.setHasFixedSize(true);
// Attach our LayoutManager to our RecyclerView
containerListRecyclerView.setLayoutManager(containerListLayoutManager);
// Wire up adapter for RecyclerView
containerListRecyclerView.setAdapter(containerListRecyclerAdapter);
cAdvisorService = new CAdvisorService();
cAdvisorService.fetchDataFromService(context, containerListRecyclerAdapter);
System.out.println("Running onCreate!");
}
I already have logic within my cAdvisorService to deal with removing and adding items into the RecyclerView.
How do I deal with the fact that onCreate is called each time, forcing new instances of my RecyclerView and cAdvisorService?