I have a splash screen using `AsyncTask`, it will download some data from database and store the data in `ArrayList`. This `ArrayList` will be used for `RecyclerView` in fragments of `MainActivity.class`. 

The problem is when I run the app from Android Studio to my phone, everything works perfectly. But, when I destroy the app and run it manually from my phone it will display blank white screen and then it will crash. And if I run once again after it crashed, the app will work. So, this app will always work only if I run it from Android Studio or after it crashed.

The error says that it is caused by the empty list. If I'm not mistaken, I think the `AsyncTask` doesn't seem to work properly after the activity is destroyed. But I don't know how to fix it. Please help me to solve this problem.

SplashScreen.java

```
public class SplashScreenActivity extends AppCompatActivity {
    public static Event event;
    private static List<Feed> feedList;
    private static List<Event> eventList;
    private static List<Event> todayList;
    private static List<Event> upcomingList;
    private static List<Partner> partnerList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splashscreen);
        Time today = new Time(Time.getCurrentTimezone());
        today.setToNow();
        Config.TODAY_DATE = String.valueOf(today.monthDay) + "-" + String.valueOf(today.month) + "-" + String.valueOf(today.year);
        new DownloadData().execute("");
    }

    class DownloadData extends AsyncTask<String, Integer, String>
    {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            startActivity(new Intent(getBaseContext(), WelcomeActivity.class));
            finish();
        }

        @Override
        protected String doInBackground(String... params) {
            RequestHandler rh = new RequestHandler();
            String JSON_STRING = rh.sendGetRequest(Config.URL_GET_ALL_DATA);
            JSONObject jsonObject;
            eventList       = new ArrayList<>();
            todayList       = new ArrayList<>();
            upcomingList    = new ArrayList<>();
            partnerList     = new ArrayList<>();
            feedList        = new ArrayList<>();
            try {
                jsonObject = new JSONObject(JSON_STRING);

                JSONArray getEvent = jsonObject.getJSONArray(Config.TAG_JSON_EVENT);
                for (int i = 0; i < getEvent.length(); i++) {
                    int id              = getEvent.getJSONObject(i).getInt(Config.TAG_ID);
                    int eoId        = getEvent.getJSONObject(i).getInt(Config.TAG_EO_ID);
                    String eoName       = getEvent.getJSONObject(i).getString(Config.TAG_EO_NAME);
                    String title        = getEvent.getJSONObject(i).getString(Config.TAG_TITLE);
                    String day      = getEvent.getJSONObject(i).getString(Config.TAG_DAY);
                    String date         = getEvent.getJSONObject(i).getString(Config.TAG_DATE);
                    int price       = getEvent.getJSONObject(i).getInt(Config.TAG_PRICE);
                    event = new Event(id, eoId, eoName, title, day, date, price);
                    eventList.add(event);
                    if(Config.TODAY_DATE.equals(event.getDate())){
                        todayList.add(event);
                    } else {
                        upcomingList.add(event);
                    }

                }

                JSONArray getPartner = jsonObject.getJSONArray(Config.TAG_JSON_PARTNER);
                for (int i = 0; i < getPartner.length(); i++) {
                    int pId         = getPartner.getJSONObject(i).getInt(Config.TAG_ID);
                    String pName    = getPartner.getJSONObject(i).getString(Config.TAG_NAME);
                    String pEmail   = getPartner.getJSONObject(i).getString(Config.TAG_EMAIL);
                    String pPhone   = getPartner.getJSONObject(i).getString(Config.TAG_PHONE);
                    String pPhoto   = getPartner.getJSONObject(i).getString(Config.TAG_PHOTO_URL);
                    Partner partner = new Partner(pId, pName, pEmail, pPhone, pPhoto);
                    partnerList.add(partner);
                }

                JSONArray getArticle = jsonObject.getJSONArray(Config.TAG_JSON_ARTICLE);
                for (int i = 0; i < getArticle.length(); i++) {
                    int feedId              = getArticle.getJSONObject(i).getInt(Config.TAG_ID);
                    String feedAuthor       = getArticle.getJSONObject(i).getString(Config.TAG_FEED_AUTHOR);
                    String feedTitle        = getArticle.getJSONObject(i).getString(Config.TAG_FEED_TITLE);
                    String feedContent      = getArticle.getJSONObject(i).getString(Config.TAG_FEED_CONTENT);
                    String feedDate         = getArticle.getJSONObject(i).getString(Config.TAG_FEED_DATE);
                    String feedThumbnail    = getArticle.getJSONObject(i).getString(Config.TAG_FEED_THUMBNAIL);
                    Feed feed = new Feed(feedId, feedAuthor, feedTitle, feedContent, feedDate, feedThumbnail);
                    feedList.add(feed);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
            return JSON_STRING;
        }

    }

    public static List<Feed> getFeedList(){ return feedList;}
    public static List<Event> getEventList() {return eventList;}
    public static List<Event> getTodayList() { return todayList;}
    public static List<Event> getUpcomingList() { return upcomingList;}
    public static List<Partner> getPartnerList() {return partnerList;}

}

```

DiscoverFragment.java

```
public class DiscoverFragment extends Fragment implements ViewPager.OnPageChangeListener, View.OnClickListener {

    protected View view;
    private LinearLayout pager_indicator;
    private int dotsCount;
    private ImageView[] dots;

    private List<Feed> feedList;
    private List<Event> eventList;
    private List<Partner> partnerList;

    public DiscoverFragment() {}

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_discover, container, false);

        RecyclerView recyclerViewEvent      = (RecyclerView) view.findViewById(R.id.discover_event_recycler_view);
        RecyclerView recyclerViewPartner    = (RecyclerView) view.findViewById(R.id.discover_partner_recycler_view);

        ClickableViewPager intro_images = (ClickableViewPager) view.findViewById(R.id.pager_introduction);
        pager_indicator         = (LinearLayout) view.findViewById(R.id.viewPagerCountDots);

        eventList       = SplashScreenActivity.getEventList();
        partnerList     = SplashScreenActivity.getPartnerList();
        feedList        = SplashScreenActivity.getFeedList();

        EventAdapter eventAdapter = new EventAdapter(getContext(), eventList);
        DiscoverPartnerAdapter discoverPartnerAdapter = new DiscoverPartnerAdapter(getContext(), partnerList);
    DiscoverFeedAdapter mAdapter = new DiscoverFeedAdapter(getContext(), feedList);

        final LinearLayoutManager layoutManagerEvent = new LinearLayoutManager(getContext());
        final LinearLayoutManager layoutManagerPartner = new LinearLayoutManager(getContext());

        layoutManagerEvent.setOrientation(LinearLayoutManager.HORIZONTAL);
        layoutManagerPartner.setOrientation(LinearLayoutManager.HORIZONTAL);

        addBottomDots(0);
        intro_images.setAdapter(mAdapter);
        intro_images.setCurrentItem(0);
        intro_images.addOnPageChangeListener(this);
        intro_images.setOnItemClickListener(new ClickableViewPager.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                Config.FEED_ID = position;
                startActivity(new Intent(getContext(), ArticleActivity.class));
            }
        });

        return view;
    }

    private void addBottomDots(int currentPage) {
        dots = new ImageView[feedList.size()]; //the problem
        pager_indicator.removeAllViews();
        for (int i = 0; i < dots.length; i++) {
            dots[i] = new ImageView(getContext());
            dots[i].setImageDrawable(getResources().getDrawable(R.drawable.nonselecteditem_dot));
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT
            );
            params.setMargins(4, 0, 4, 0);
            pager_indicator.addView(dots[i], params);
        }
        if (dots.length > 0)
            dots[currentPage].setImageDrawable(getResources().getDrawable(R.drawable.selecteditem_dot));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }

    @Override
    public void onPageSelected(int position) {
        addBottomDots(position);
        for (int i = 0; i < dotsCount; i++) {
            dots[i].setImageDrawable(getResources().getDrawable(R.drawable.nonselecteditem_dot));
        }
        dots[position].setImageDrawable(getResources().getDrawable(R.drawable.selecteditem_dot));
    }
}

```

LogCat

```
01-29 00:40:57.565 32535-32535/com.irmaelita.esodiaapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.irmaelita.esodiaapp, PID: 32535
                                                                         java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
                                                                             at com.irmaelita.esodiaapp.fragment.DiscoverFragment.addBottomDots(DiscoverFragment.java:181)
                                                                             at com.irmaelita.esodiaapp.fragment.DiscoverFragment.onCreateView(DiscoverFragment.java:158)

```