Android: onClick StartActivity works only when there is no internet connection
<p>I have a method on my app which displays random images from the SQLite database, which are fetched from the web (JSON).
I put an OnClickListener to the image so when it's clicked, it will lead to a new Activity carrying the properties (from JSON saved into an SQLite database) of the random shown image through a Cursor.</p>

<p>The problem I'm facing is, the images are clickable and lead to a new Activity, only when my device isn't connected to the internet.</p>

<p>Can anybody analyze my code below and provide me a solution? Thank you in advance.</p>

<pre><code>HashMap&lt;ImageView, Long&gt; aaa = new HashMap&lt;ImageView, Long&gt;();

final ImageView[] images = new ImageView[3];
        ImageLoader loader = new ImageLoader(this);

        images[0] = (ImageView)findViewById(R.id.top1);
        images[1] = (ImageView)findViewById(R.id.top2);
        images[2] = (ImageView)findViewById(R.id.top3);

        images[0].setOnClickListener(this);
        images[1].setOnClickListener(this);
        images[2].setOnClickListener(this);

        int counter = 0;

            Cursor c = managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
                            Database.Project.NAME), new String[] { BaseColumns._ID,
                            Database.Project.C_SMALLIMAGE}, null, null, "RANDOM() LIMIT 3");
          if(c!=null &amp;&amp; c.moveToFirst()){
             do{
               String url = c.getString(1);
               images[counter].setTag(url);
               loader.DisplayImage(url, this, images[counter]);
               aaa.put(images[counter], c.getLong(c.getColumnIndex(BaseColumns._ID)));
               counter++;
             }while(c.moveToNext());
          }

@Override
        public void onClick(View v)
        {
            Intent listIntent = new Intent(MainActivity.this, DetailsActivity.class);
            long id = aaa.get(v);
            listIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
                    Provider.CONTENT_URI, Database.Project.NAME), Long
                    .toString(id)));
            startActivity(listIntent);
        }
</code></pre>

<p>DetailsActivity class.</p>

<pre><code>public class DetailsActivity extends Activity implements OnClickListener {

    ImageLoader loader = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.project);
        loader = new ImageLoader(this);
            Intent intent = getIntent();
            if (intent != null) {
                Uri uri = intent.getData();
                if (uri != null) {
                    Cursor cursor = managedQuery(uri, new String[] {
                            BaseColumns._ID, Database.Project.C_PROJECTTITLE, Database.Project.C_ORGANIZATIONTITLE,
                            Database.Project.C_PROJECTDESCRIPTION,Database.Project.C_SMALLIMAGE}, null, null, null);

                    if (cursor == null) {
                        finish();
                    } else {
                        if (cursor.moveToFirst()) {
                            ImageView img = (ImageView) findViewById(R.id.project_image);
                            TextView project_title = (TextView)findViewById(R.id.txt_project_title);
                               project_title.setText(cursor.getString(1));

                               TextView organization_title = (TextView)findViewById(R.id.txt_organization_title);
                               organization_title.setText(Html.fromHtml("von " +cursor.getString(2)));

                               TextView project_description = (TextView)findViewById(R.id.txt_project_description);
                               project_description.setText(Html.fromHtml(cursor.getString(3)));
                                String imageUrl = cursor.getString(4);
                                img.setTag(imageUrl);
                                loader.DisplayImage(imageUrl, this, img);


                        } else {
                            finish();
                        }

                    }
                }
            }   

    }
</code></pre>
