Search code examples
javaandroidandroid-viewpagerswiperefreshlayout

Android (Java) ViewPager with Fragments after weakup mSwipeRefreshLayout send error


My app has a main activity with ViewPager and three tabs with Fragments. Each Fragment is a ListView with SwipeRefreshLayout. If my app goes in background - 3-5 hours, I think, it gets loaded from taskmanager, it reloaded and it is fork. But if I call fragment from main activity (i call another activity with filter) with code

@Override
public void onRefresh() {


    if (mSwipeRefreshLayout != null) {
        // начинаем показывать прогресс
        mSwipeRefreshLayout.setRefreshing(true);

        // ждем 3 секунды и прячем прогресс
        mSwipeRefreshLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                arrayVideo.clear();
                adapter.notifyDataSetInvalidated();
                offset = 0;
                isEnd = false;
                loadVideoList(limit, offset,
                        activity.settings.getString("videoFilterName", ""),
                        activity.settings.getInt("videoFilterSector", 0),
                        activity.settings.getInt("videoFilterNumber", 0),
                        activity.settings.getInt("videoFilterMain", 0));
                offset += limit;

                // говорим о том, что собираемся закончить
                //  Toast.makeText(MainActivity.this, R.string.refresh_finished, Toast.LENGTH_SHORT).show();
            }
        }, 500);
    }
}  

it causes a crash.

Questions: 1) how am I repeatedly getting this error ? What actions is needed? (onStop.....) 2) What I am doing wrong?


Solution

  • I got it, this is truth call to Fragments from parent Activity:

    VideoListFragment videoListFragment = (VideoListFragment) pagerAdapter.instantiateItem(mViewPager, TAB_VIDEO);