views:

67

answers:

1

hi,

I am new in android and had developed an app which get images from the website and display it. I got it working in emulator but not in real phones. In some device, it will crash or take very long loading period. Can anyone please help me or guide me in improving it as i'm not sure whether the way i loads the images is correct or not.

Here are the code i use to get the images from the web and display accordingly.

if (xmlURL.length() != 0) {


 try {
    URL url = new URL(xmlURL);
     SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();

/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
/*
 * Create a new ContentHandler and apply it to the
 * XML-Reader
 */
xr.setContentHandler(myExampleHandler);

/* Parse the xml-data from our URL. */
xr.parse(new InputSource(url.openStream()));
/* Parsing has finished. */

/*
 * Our ExampleHandler now provides the parsed data to
 * us.
 */
ParsedExampleDataSet parsedExampleDataSet = myExampleHandler.getParsedData();



 } catch (Exception e) {

   }
  }

  if (s.equalsIgnoreCase("wallpapers")) {
   Context context = helloAndroid.this.getBaseContext();

   for (int j = 0; j <= myExampleHandler.filenames.size() - 1; j++) {
    if (myExampleHandler.filenames.elementAt(j).toString() != null) {
     helloAndroid.this.ed = myExampleHandler.thumbs.elementAt(j)
       .toString();
     if (helloAndroid.this.ed.length() != 0) {
      Drawable image = ImageOperations(context,
        helloAndroid.this.ed, "image.jpg");
      file_info = myExampleHandler.filenames
        .elementAt(j).toString();
      author = "\nby "
        + myExampleHandler.authors.elementAt(j)
          .toString();
      switch (j + 1) {
      case 1:
       ImageView imgView1 = new ImageView(context);
       imgView1 = (ImageView) findViewById(R.id.image1);
       if (image.getIntrinsicHeight() > 0) {
        imgView1.setImageDrawable(image);
       } else
        imgView1
          .setImageResource(R.drawable.empty_wallpaper);
       tv = (TextView) findViewById(R.id.filename1);
       tv.setText(file_info);
       tv = (TextView) findViewById(R.id.author1);
       tv.setText(author);
       imgView1
         .setOnClickListener(new View.OnClickListener() {
          public void onClick(View view) {
           // Perform action on click
           Intent myIntent1 = new Intent(
             helloAndroid.this,
             galleryFile.class);
           Bundle b = new Bundle();
           b.putString("fileID",myExampleHandler.fileid.elementAt(0).toString());
           b.putString("page", "1");
           b.putString("family", s);
           b.putString("fi",myExampleHandler.folder_id.elementAt(folder).toString());
           b.putString("kw", keyword);
           myIntent1.putExtras(b);
        startActivityForResult(
             myIntent1, 0);
          }
         });
       break;
      case 2:
       ImageView imgView2 = new ImageView(context);
       imgView2 = (ImageView) findViewById(R.id.image2);
       imgView2.setImageDrawable(image);
       tv = (TextView) findViewById(R.id.filename2);
       tv.setText(file_info);
       tv = (TextView) findViewById(R.id.author2);
       tv.setText(author);
       imgView2
         .setOnClickListener(new View.OnClickListener() {
          public void onClick(View view) {
           // Perform action on click
           Intent myIntent1 = new Intent(
             helloAndroid.this,
             galleryFile.class);
           Bundle b = new Bundle();
           b.putString("fileID",myExampleHandler.fileid.elementAt(1).toString());
           b.putString("page", "1");
           b.putString("family", s);
           b.putString("fi",myExampleHandler.folder_id.elementAt(folder).toString());
           b.putString("kw", keyword);
           myIntent1.putExtras(b);
        startActivityForResult(
             myIntent1, 0);
          }
         });
       break;
      case 3:
       //same code
   break;
  }
 }
}


  }
  }
    private Drawable ImageOperations(Context ctx, String url,
   String saveFilename) {
  try {
   InputStream is = (InputStream) this.fetch(url);
   Drawable d = Drawable.createFromStream(is, "src");
   return d;
  } catch (MalformedURLException e) {
   e.printStackTrace();
   return null;
  } catch (IOException e) {
   e.printStackTrace();
   return null;
  }
 }

 public Object fetch(String address) throws MalformedURLException,
   IOException {
  URL url = new URL(address);
  Object content = url.getContent();
  return content;
 }
A: 

Yes, you can get logcat from your device are you aware of how to connect to usb and push the file over via adb commands?

Fred Grott
erm... i am not aware of it. however, i do not have the device with me as well as i send my apps to testers from other countries. Is there any other ways i could get the logcat or how can i get the logcat from the mobile owner?
Lynnooi
do a google search there are two or more libs that allow you to do that..ie get logcat and error trace form mobile device user to debug via putting those libs i n your application and calling a few methods..Two libs Log Collector and stack trace collectorLink for stack trace:http://code.google.com/p/android-remote-stacktraceYou will l need to set Read.logs in your manifest and of course internet permission so you can get the error report via http form the user
Fred Grott
Ok.. Thanks a lot. i will try to get the log cat and update it here. =)
Lynnooi
By the way, can you all teach me on how to modify my code so that i can grab my images in separate thread? ask i had try previously got cant make it right. I want to put it in another thread is because i want to display a loading image while it is loading.
Lynnooi
search the main android dev blog Romain Guy did a blog post on that several months ago or search anddev.org forums
Fred Grott