I have a ViewPager in which 3 fragments. Inside each of the RecycleView fragments
In the fragment I make a request to the server, receive data and transfer it to the adapter:
call.enqueue(new Callback<String>() { @Override public void onResponse(Call<SomeObj> call, Response<String> response) { HistoryAdapter adapter = new HistoryAdapter(context, someObj); listView.setAdapter(adapter); } @Override public void onFailure(Call<SomeObj> call, Throwable t) { } }); Adapter Code:
public class HistoryAdapter extends RecyclerView.Adapter<HistoryAdapter.ViewHolder> { SomeObj histories; public HistoryAdapter(SomeObject histories, Context context){ this.histories = histories; this.context = context; } //ТУт другие методы по заполнению ячейки итп. public static class ViewHolder extends RecyclerView.ViewHolder{ LinearLayout player_preview; TextView artist; TextView track; ImageView cover; ImageView play_pause_button; TextView time_history; public ViewHolder(View itemView) { super(itemView); player_preview = (LinearLayout)itemView.findViewById(R.id.player_preview); artist = (TextView) itemView.findViewById(R.id.artist_history); track = (TextView) itemView.findViewById(R.id.track_history); play_pause_button = (ImageView) itemView.findViewById(R.id.playPauseButton_history); time_history = (TextView) itemView.findViewById(R.id.time_history); cover = (ImageView) itemView.findViewById(R.id.cover_history); } } } The question is that after the user walks through the fragments or turns the screen, the Fragments are deleted from the memory. But the Adapter continues to hang in memory because of static ViewHolder and the application catches OutOfMemory. How to solve this problem?
Но Адаптер продолжает висеть в памяти из-за static ViewHolder- static in a class declaration is not the same as static in a field, so no, not because of this, it continues to hang (if it hangs at all). - post_zeew