android - Running multiple AsyncTask exits the application without showing any specific error -


i have simple task in application.i trying achieve following in application.

1.capturing image using custom camera class when hardware volume button pressed.and once capturing started, should automatically capture images @ regular interval(lets 2 sec).

2.each images had saved in sd card , mail corresponding mail id in background.

in order achieve above created custom camera class , override hardware volume button capture picture.and send mail in background used java mail api.

as have send mail @ each 2 sec of interval, wrote mailing , saving sd card code using asynctask. find out here , other posts pool size of asynctask max 128+10=138 total.as sending mail @ 2 sec interval,it exceed max pool size results error.

but requirement capture high resolution images @ 2 sec interval , mail corresponding mail id.

is possible using asynctask? or other framework android provides execute long running tasks?

below have tried far,

hardware volume key override

 public boolean onkeydown(int keycode, keyevent event)          {             if (keycode == keyevent.keycode_volume_down || keycode == keyevent.keycode_volume_up) {                   timer = new timer();                 timertask updateprofile = new customtimertask(dvcameraactivity.this);                 timer.scheduleatfixedrate(updateprofile, 0, 2000);                 toast toast= toast.maketext(getapplicationcontext(), "picture capturing started..", toast.length_long);                 toast.setgravity(gravity.center_vertical, 0, 0);                 toast.show();            return true;        } else {            return super.onkeydown(keycode, event);         }     } 

customtimertask

public class customtimertask extends timertask {         public customtimertask(context con) {         }         @override         public void run() {              if (iscamera == true)                 mcamera.takepicture(null, null, mpicture);         }      } 

picturecallback

picturecallback mpicture = new picturecallback() {         @override         public void onpicturetaken(byte[] data, camera camera) {             new savephototask().execute(data);              if (mcamera!= null)             camera.startpreview();         }      }; 

savephototask()

class savephototask extends asynctask<byte[], string, string> {         @suppresslint("simpledateformat")         @override         protected string doinbackground(byte[]... jpeg) {               file mediastoragedir = new file(                     environment                             .getexternalstoragepublicdirectory(environment.directory_pictures),                     "secret camera");              if (!mediastoragedir.exists()) {                 if (!mediastoragedir.mkdirs()) {                     log.d("mycameraapp", "failed create directory");                     return null;                 }             }              string timestamp = new simpledateformat("yyyymmdd_hhmmss")                     .format(new date());             file mediafile;             mediafile = new file(mediastoragedir.getpath() + file.separator                     + "img_" + timestamp + "." + msuffix);             try {                 fileoutputstream fos = new fileoutputstream(mediafile);                 fos.write(jpeg[0]);                 fos.close();                  path=mediafile.getabsolutepath();                 sendmail(path);             } catch (filenotfoundexception e) {              } catch (ioexception e) {             }              return mediafile.tostring();         }          @override         protected void onpostexecute(string result) {             super.onpostexecute(result);           }       } 

sendmail()

private void sendmail(string imagepath) {         mail m = new mail(constants.email, constants.psw);         string[] toarr = { constants.email };         m.setto(toarr);         m.setfrom("<email>");         m.setsubject("spy camera images");         m.setbody("if watching image, spy camera app working..voila!!");         try {             m.addattachment(imagepath);             if (m.send()) {                 log.i("mail send", "successs");                 send=true;             } else {                 send=false;                 log.i("mail send", "failed");             }         } catch (exception e) {             log.e("mailapp", "could not send email", e);         }     } 

logcat error

08-23 18:37:55.609: i/dalvikvm(12540): dalvik threads: 08-23 18:37:55.609: i/dalvikvm(12540): "main" prio=5 tid=1 wait 08-23 18:37:55.609: i/dalvikvm(12540):   | group="main" scount=1 dscount=0 s=n obj=0x401b8968 self=0xcd38 08-23 18:37:55.609: i/dalvikvm(12540):   | systid=12540 nice=0 sched=0/0 cgrp=default handle=-1345017816 08-23 18:37:55.609: i/dalvikvm(12540):   @ java.lang.object.wait(native method) 08-23 18:37:55.609: i/dalvikvm(12540):   - waiting on <0x48718010> (a android.os.messagequeue) 08-23 18:37:55.609: i/dalvikvm(12540):   @ java.lang.object.wait(object.java:288) 08-23 18:37:55.617: i/dalvikvm(12540):   @ android.os.messagequeue.next(messagequeue.java:146) 08-23 18:37:55.617: i/dalvikvm(12540):   @ android.os.looper.loop(looper.java:110) 08-23 18:37:55.624: i/dalvikvm(12540):   @ android.app.activitythread.main(activitythread.java:4632) 08-23 18:37:55.624: i/dalvikvm(12540):   @ java.lang.reflect.method.invokenative(native method) 08-23 18:37:55.624: i/dalvikvm(12540):   @ java.lang.reflect.method.invoke(method.java:521) 08-23 18:37:55.624: i/dalvikvm(12540):   @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:871) 08-23 18:37:55.624: i/dalvikvm(12540):   @ com.android.internal.os.zygoteinit.main(zygoteinit.java:629) 08-23 18:37:55.624: i/dalvikvm(12540):   @ dalvik.system.nativestart.main(native method) 08-23 18:37:55.624: i/dalvikvm(12540): "asynctask #34" prio=5 tid=42 monitor 

sorry such lengthy explanation. couldn't find shorter way explain problem. suggestion appreciated. lot.

create own queue of requests, put each "send picture" request in queue, , use 1 mail task process requests queue. use single connection send requests queue until queue empty, close connection , wait next request.


Comments

Popular posts from this blog

c++ - Linked List error when inserting for the last time -

java - activate/deactivate sonar maven plugin by profile? -

java - What is the difference between String. and String.this. ? -