Android ArrayAdapter, AsyncTaskLoader. Duplicate items when switching orientation
<p>The AsynctaskLoader is called multiple times and I get 3 items (2 duplicates) on the listfragment. (I do not want to clear, since I want to implement an endless scroller). If I remove items (adapter.remove) when onLoadFinished is called I still get two items (one duplicate). If i call adapter.clear onLoadFinished I get 1 item, but can't implement an endless scroller then. The endless scroller is implemented by calling a loader with a new idea and a new bundle.</p>

<pre><code>        public class ArticlePreviewAdapter extends ArrayAdapter&lt;ArticlePreview&gt;  {

        private final LayoutInflater inflater;
        private final ImageUpdater imageUpdater;



        public ArticlePreviewAdapter(Context context, ImageUpdater imageUpdater) {
            super(context, android.R.layout.simple_list_item_1);
            android.util.Log.d("SCROLL", "ArticlePreviewAdapter.ArticlePreviewAdapter" );

            this.inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);     
            this.imageUpdater = imageUpdater;
        }


        public void setData(ArticlePreview data) {
            //clear();      
            if (data != null) {         
                add(data);
                //this.add(data);           
            }
        }   

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            View view;

            if (convertView == null) {
                view = inflater.inflate(R.layout.article_preview, parent, false);
            } 
            else {
                view = convertView;
            }

            ArticlePreview articlePreview = getItem(position);      

            android.util.Log.d("SCROLL", "ArticlePreviewAdapter.getView pos: " + position);

            ((TextView) view.findViewById(R.id.article_preview_title)).setText(articlePreview.getTitle());
            ((TextView) view.findViewById(R.id.article_preview_info)).setText(articlePreview.getInfo());

            ImageView imageView = ((ImageView) view.findViewById(R.id.article_preview_image));
            Bitmap bitmap = this.imageUpdater.accessDirectly(articlePreview.getImageLink());

            if (bitmap != null) {
                imageView.setImageBitmap(bitmap);
            }
            else {
                this.imageUpdater.add(new ImageViewWebUpdate(view.hashCode(),
                        imageView, 100, 75, articlePreview.getImageLink()));
            }       

            return view;
        }
        }
</code></pre>

<p>The Loader class</p>

<pre><code>public class ArticlePreviewLoader extends AsyncTaskLoader&lt;List&lt;ArticlePreview&gt;&gt;
{

    private String type;
    private String nid;
    private String start;
    private String end;

    private List&lt;ArticlePreview&gt; data;

    public ArticlePreviewLoader(Context context, Bundle args)
    {
        super(context);

        this.type = (String) args.get("type");
        this.nid = (String) args.get("nid");
        this.start = (String) args.get("start");
        this.end = (String) args.get("end");
    }

    /**
     * load JSON data, parse it and return.
     */
    @Override
    public List&lt;ArticlePreview&gt; loadInBackground()
    {

        android.util.Log.d("LOAD", "ArticlePreviewLoader.loadInBackground");

        // even if fail return empty list and print exception stack trace
        LinkedList&lt;ArticlePreview&gt; list = new LinkedList&lt;ArticlePreview&gt;();
        URL url;
        HttpURLConnection httpURLConnection = null;

        --

        android.util.Log.d("LOAD", "ArticlePreviewLoader.loadInBackground return");

        return Collections.unmodifiableList(list);
        //return list;
    }

    @Override
    protected void onStartLoading()
    {

        if (data != null)
            deliverResult(data);

        if (takeContentChanged() || data == null)
            forceLoad();
    }

    @Override
    protected void onStopLoading()
    {

        //super.onStopLoading();
        cancelLoad();
    }

    @Override
    protected void onReset()
    {
        super.onReset();

        onStopLoading();
        data = null;
    }
}
</code></pre>

<p>Help would be appreciated.. I'm stuck on this for a day now.</p>

<p><strong>EDIT</strong></p>

<p>Manifest code: 
    </p>

<pre><code>    &lt;uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="16" /&gt;

    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;

     &lt;!-- Permission to write to external storage --&gt;
    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;

    &lt;application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" &gt;
        &lt;activity
            android:name=".SplashActivity"
            android:label="@string/title_activity_splash" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &lt;activity
            android:name=".LoginActivity"
            android:label="@string/title_activity_login" &gt;
        &lt;/activity&gt;
        &lt;activity
            android:name=".ArticleForumActivity"
            android:label="@string/title_activity_article_forum" &gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>
