Saturday, 15 January 2011

Android app debugging on real device -



Android app debugging on real device -

i testing lastly android app on real device , crashes on sec screen.

tested on simulator works fine.

this debugging message when crashes.....

any help welcome find out begin solve issue.

10-22 21:31:09.364: e/windowmanager(31009): android.view.windowleaked: activity com.solinpromex.casajuventudtrescantos.cursos_mainactivity has leaked window com.android.internal.policy.impl.phonewindow$decorview{456e0908 v.e..... r......d 0,0-580,163} added here 10-22 21:31:09.364: e/windowmanager(31009): @ android.view.viewrootimpl.<init>(viewrootimpl.java:468) 10-22 21:31:09.364: e/windowmanager(31009): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:267) 10-22 21:31:09.364: e/windowmanager(31009): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 10-22 21:31:09.364: e/windowmanager(31009): @ android.app.dialog.show(dialog.java:289) 10-22 21:31:09.364: e/windowmanager(31009): @ com.solinpromex.casajuventudtrescantos.cursos_mainactivity$downloadjson.onpreexecute(cursos_mainactivity.java:77) 10-22 21:31:09.364: e/windowmanager(31009): @ android.os.asynctask.executeonexecutor(asynctask.java:587) 10-22 21:31:09.364: e/windowmanager(31009): @ android.os.asynctask.execute(asynctask.java:535) 10-22 21:31:09.364: e/windowmanager(31009): @ com.solinpromex.casajuventudtrescantos.cursos_mainactivity.onresume(cursos_mainactivity.java:145) 10-22 21:31:09.364: e/windowmanager(31009): @ android.app.instrumentation.callactivityonresume(instrumentation.java:1198) 10-22 21:31:09.364: e/windowmanager(31009): @ android.app.activity.performresume(activity.java:5538) 10-22 21:31:09.364: e/windowmanager(31009): @ android.app.activitythread.performresumeactivity(activitythread.java:3053) 10-22 21:31:09.364: e/windowmanager(31009): @ android.app.activitythread.handleresumeactivity(activitythread.java:3092) 10-22 21:31:09.364: e/windowmanager(31009): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2463) 10-22 21:31:09.364: e/windowmanager(31009): @ android.app.activitythread.access$900(activitythread.java:172) 10-22 21:31:09.364: e/windowmanager(31009): @ android.app.activitythread$h.handlemessage(activitythread.java:1305) 10-22 21:31:09.364: e/windowmanager(31009): @ android.os.handler.dispatchmessage(handler.java:102) 10-22 21:31:09.364: e/windowmanager(31009): @ android.os.looper.loop(looper.java:146) 10-22 21:31:09.364: e/windowmanager(31009): @ android.app.activitythread.main(activitythread.java:5598) 10-22 21:31:09.364: e/windowmanager(31009): @ java.lang.reflect.method.invokenative(native method) 10-22 21:31:09.364: e/windowmanager(31009): @ java.lang.reflect.method.invoke(method.java:515) 10-22 21:31:09.364: e/windowmanager(31009): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1283) 10-22 21:31:09.364: e/windowmanager(31009): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1099) 10-22 21:31:09.364: e/windowmanager(31009): @ dalvik.system.nativestart.main(native method)

activity code added:

package com.solinpromex.casajuventudtrescantos; import android.content.dialoginterface.onclicklistener; import android.content.intent; import android.graphics.bitmap; import android.graphics.color; import android.os.bundle; import android.util.log; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.motionevent; import android.view.view; import android.view.viewgroup; import android.widget.button; import android.widget.imageview; import android.os.build; import android.app.activity; import android.widget.toast; public class mainactivity extends activity implements view.ontouchlistener { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); imageview iv = (imageview) findviewbyid (r.id.image); if (iv != null) { iv.setontouchlistener (this); } } public boolean ontouch (view v, motionevent ev) { boolean handledhere = false; final int action = ev.getaction(); final int evx = (int) ev.getx(); final int evy = (int) ev.gety(); int nextimage = -1; // resource id of next image display // if cannot find imageview, return. imageview imageview = (imageview) v.findviewbyid (r.id.image); if (imageview == null) homecoming false; // when action down, see if should show "pressed" image default image. // when default image showing. status detectable looking @ // tag of view. if null or contains resource number of default image, display pressed image. integer tagnum = (integer) imageview.gettag (); int currentresource = (tagnum == null) ? r.drawable.p2_ship_default : tagnum.intvalue (); // know current resource beingness displayed can handle downwards , events. switch (action) { case motionevent.action_down : if (currentresource == r.drawable.p2_ship_default) { // nextimage = r.drawable.p2_ship_pressed; handledhere = true; /* } else if (currentresource != r.drawable.p2_ship_default) { nextimage = r.drawable.p2_ship_default; handledhere = true; */ } else handledhere = true; break; case motionevent.action_up : // on up, click action. // hidden image (image_areas) has 3 different hotspots on it. // colors red, blue, , yellow. // utilize image_areas determine part user touched. int touchcolor = gethotspotcolor (r.id.image_areas, evx, evy); // compare touchcolor expected values. switch different image, depending on color touched. // note utilize color tool object test whether observed color close plenty real color // count match. because colors on screen not match map because of scaling , // varying pixel density. colortool ct = new colortool (); int tolerance = 25; // nextimage = r.drawable.p2_ship_default; if (ct.closematch (color.red, touchcolor, tolerance)) { toast.maketext(getapplicationcontext(), "casa de la juventud", toast.length_long).show(); intent intent = new intent(mainactivity.this, categorias_list.class); startactivity(intent); } else if (ct.closematch (color.yellow, touchcolor, tolerance)) { toast.maketext(getapplicationcontext(), "zonas oficiales", toast.length_long).show(); intent intent = new intent(mainactivity.this, categorias_list.class); startactivity(intent); } else if (ct.closematch (color.rgb(164,199,57) , touchcolor, tolerance)) { toast.maketext(getapplicationcontext(), "zonas wi-fi", toast.length_long).show(); intent intent = new intent(mainactivity.this, categorias_list.class); startactivity(intent); } else if (ct.closematch (color.ltgray , touchcolor, tolerance)) { toast.maketext(getapplicationcontext(), "zona deportes", toast.length_long).show(); intent intent = new intent(mainactivity.this, categorias_list.class); startactivity(intent); } else if (ct.closematch (color.blue , touchcolor, tolerance)) { toast.maketext(getapplicationcontext(), "zona copas", toast.length_long).show(); intent intent = new intent(mainactivity.this, categorias_list.class); startactivity(intent); } else if (ct.closematch (color.white , touchcolor, tolerance)) { toast.maketext(getapplicationcontext(), "zona quedadas", toast.length_long).show(); intent intent = new intent(mainactivity.this, categorias_list.class); startactivity(intent); } else if (ct.closematch (color.black , touchcolor, tolerance)) { toast.maketext(getapplicationcontext(), "zona cultura", toast.length_long).show(); intent intent = new intent(mainactivity.this, cursos_mainactivity.class); startactivity(intent); } // if next image same lastly image, go default. // toast ("current image: " + currentresource + " next: " + nextimage); if (currentresource == nextimage) { nextimage = r.drawable.p2_ship_default; } handledhere = true; break; default: handledhere = false; } // end switch if (handledhere) { if (nextimage > 0) { imageview.setimageresource (nextimage); imageview.settag (nextimage); } } homecoming handledhere; } public void openofertas(view view) { intent intent = new intent(mainactivity.this, categorias_list.class); startactivity(intent); } public void openartesania(view view) { intent intent = new intent(mainactivity.this, artesania_mainactivity.class); startactivity(intent); } public void opencursos(view view) { intent intent = new intent(mainactivity.this, cursos_mainactivity.class); startactivity(intent); } public void openavisos(view view) { intent intent = new intent(mainactivity.this, avisos_mainactivity.class); startactivity(intent); } public void openmapa(view view) { intent intent = new intent(mainactivity.this, mapa_mainactivity.class); startactivity(intent); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); } public int gethotspotcolor (int hotspotid, int x, int y) { imageview img = (imageview) findviewbyid (hotspotid); if (img == null) { log.d ("imageareasactivity", "hot spot image not found"); homecoming 0; } else { img.setdrawingcacheenabled(true); bitmap hotspots = bitmap.createbitmap(img.getdrawingcache()); if (hotspots == null) { log.d ("imageareasactivity", "hot spot bitmap not created"); homecoming 0; } else { img.setdrawingcacheenabled(false); homecoming hotspots.getpixel(x, y); } } } }

added activity cursos_mainactivity

package com.solinpromex.casajuventudtrescantos; import java.util.arraylist; import java.util.hashmap; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import android.app.activity; import android.app.progressdialog; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.util.log; import android.widget.listview; public class cursos_mainactivity extends activity { // declare variables jsonobject jsonobject; jsonarray jsonarray; listview listview; cursos_listviewadapter adapter; progressdialog mprogressdialog; arraylist<hashmap<string, string>> arraylist; static string valoracionartesano = "valoracionartesano"; static string nombreartesano = "nombreartesano"; static string direccionartesano = "direccionartesano"; static string logoartesano = "logoartesano"; static string telefonoartesano = "telefonoartesano"; static string facebookartesano = "facebookartesano"; static string emailartesano = "emailartesano"; static string textartesano = "textartesano"; static string latitud = "latitud"; static string longitud = "longitud"; static string idartesano = "idartesano"; static string ciudad = "ciudad"; static string cp = "cp"; static string web = "web"; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.v("mvasco", "context null!"); // getting intent info intent in = getintent(); // json node keys this.settitle("zona cultura"); // view listview_main.xml setcontentview(r.layout.cursos_listview_main); // execute downloadjson asynctask //new downloadjson().execute(); } // downloadjson asynctask private class downloadjson extends asynctask<void, void, void> { @override protected void onpreexecute() { super.onpreexecute(); // create progressdialog mprogressdialog = new progressdialog(cursos_mainactivity.this); // set progressdialog title mprogressdialog.settitle("casa de la juventud"); // set progressdialog message mprogressdialog.setmessage("zona cultura"); mprogressdialog.setindeterminate(false); // show progressdialog mprogressdialog.show(); } @override protected void doinbackground(void... params) { // create array arraylist = new arraylist<hashmap<string, string>>(); // retrieve json objects given url address jsonobject = jsonfunctions .getjsonfromurl("http://www.solinpromex.com/casajuventud/android/android_centros.php"); seek { // locate array name in json jsonarray = jsonobject.getjsonarray("categorias"); (int = 0; < jsonarray.length(); i++) { hashmap<string, string> map = new hashmap<string, string>(); jsonobject = jsonarray.getjsonobject(i); // retrive json objects string codpostal = jsonobject.getstring("cp_zonacultura"); map.put("valoracionartesano", jsonobject.getstring("valoracion_zonacultura")); map.put("nombreartesano", jsonobject.getstring("nombre_zonacultura")); map.put("direccionartesano", jsonobject.getstring("direccion_zonacultura")); map.put("logoartesano", jsonobject.getstring("imagen_zonacultura")); map.put("telefonoartesano", jsonobject.getstring("tel_zonacultura")); map.put("emailartesano", jsonobject.getstring("email_zonacultura")); map.put("textartesano", jsonobject.getstring("desc_zonacultura")); map.put("facebookartesano", jsonobject.getstring("facebook_zonacultura")); map.put("latitud", jsonobject.getstring("latitud_zonacultura")); map.put("longitud", jsonobject.getstring("longitud_zonacultura")); map.put("idartesano", jsonobject.getstring("id_zonacultura")); map.put("ciudad", codpostal+" "+jsonobject.getstring("ciudad_zonacultura")); map.put("cp", jsonobject.getstring("cp_zonacultura")); map.put("web", jsonobject.getstring("web_zonacultura")); log.d("nombre del sitio ", "value: " + (jsonobject.getstring("nombre_zonacultura"))); // set json objects array arraylist.add(map); } } grab (jsonexception e) { log.e("error", e.getmessage()); e.printstacktrace(); } homecoming null; } @override protected void onpostexecute(void args) { // locate listview in listview_main.xml listview = (listview) findviewbyid(r.id.listview); // pass results listviewadapter.java adapter = new cursos_listviewadapter(cursos_mainactivity.this, arraylist); // set adapter listview listview.setadapter(adapter); // close progressdialog mprogressdialog.dismiss(); } } @override protected void onresume() { // todo auto-generated method stub super.onresume(); new downloadjson().execute(); } }

i think problem in :

adapter = new cursos_listviewadapter(cursos_mainactivity.this, arraylist); // set adapter listview listview.setadapter(adapter);

i have no thought in adapter usual dealing there views.

don't forget "onpostexecute" still in other thread , trying work views main thread/activity ...

the best solution things pass asynctask interface , when done asynctask pass info activity.

this much more close solid. asynctask shall info , pass over. adapter shall shown received data.

android

No comments:

Post a Comment