java - Android service stops after less than 5 minutes -
i creating android application needs send udp packets server.
the problem after 2-5 minutes, after screen off, service stops sending data, until turn screen on (can confirm on server side).
here service start command:
startservice(new intent(getbasecontext(), service.class)); the onstartcommand:
@override public int onstartcommand(intent intent, int flags, int startid){     toast.maketext(this, "armed!", toast.length_long).show();     (new thread(new app())).start();     return start_redeliver_intent; } and run method, app thread:
public void run(){     vibrator alarm = (vibrator) mainactivity.getappcontext().getsystemservice(context.vibrator_service);     string ip = getwifiip(mainactivity.getappcontext());      while(true){         while (ip.equals(wifiaddr)){ //confirm presence on local network, host             //unlocked door             system.out.println("started locally!");             senddata(key, hostaddrlocal);             try {                 thread.sleep(5000);             } catch (interruptedexception e) {                 e.printstacktrace();             }             ip = getwifiip(mainactivity.getappcontext());         }    } } i positive not running out of memory, have no other applications up, running on galaxy s4, lollipop 5.0
is because interacting main activity, context mainactivity.getappcontext() ?
i tried many things, including sticky_service.
the problem after 2-5 minutes, after screen off, service stops sending data, until turn screen on (can confirm on server side).
the cpu has powered down, has wifi radio, in likelihood. need acquire wakelock , wifilock keep both powered on. ordinary users ordinary hardware, keeping cpu , wifi radio on time very unpopular due battery drain.
Comments
Post a Comment