@Override public void onDestroy() { super.onDestroy(); // Close adapter. if (adapter != null) adapter.close(); // Close Realm. if (realm != null) { realm.close(); realm = null; } if (actionMode != null) actionMode.finish(); }
/** * Uses the current view options to change the card layout currently in use. Preserves the * position currently scrolled to in the list before switching adapters. */ private void changeCardType() { // Store the current last visible item position so that we can scroll back to it after switching // adapters. int currLastVisPos = recyclerView.getLayoutManager().findLastCompletelyVisibleItemPosition(); // Swap the adapter if (adapter != null) adapter.close(); adapter = makeAdapter(); recyclerView.setAdapter(adapter); // Scroll back to the same position. if (currLastVisPos != RecyclerView.NO_POSITION) recyclerView.getRecyclerView().scrollToPosition(currLastVisPos); }