2016-01-20 47 views
0

在我的Android清單中,我指定了一個parentActivityName以利用活動中顯示的後退按鈕。parentActivityName forces onCreate

我發現這個不過是重新調用onCreate之前的活動,其中我做了幾次網絡調用並設置了一個回收站視圖控件。

這會導致屏幕完全刷新,我想避免這種情況,並處理recyclerview以及顯示和刪除哪些新內容以確保用戶流不會顛簸。

我現在把我的應用起來的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!"); 
} 

我已經有我的cAdvisorService內的邏輯來處理刪除和添加項目到RecyclerView。

我該如何處理每次調用onCreate的事實,強制執行我的RecyclerView和cAdvisorService的新實例?

回答