How to resolve this error in android - java.lang.RuntimeException: Only one Looper may be created per thread -


here code in background service

public class backgroundservice extends service {     private int interval1 = 60; // 60 seconds     private int interval2 = 60; // 60 seconds     //=============================================================================================================================     private handler mtimer1 = new handler();     private runnable mtask1 = new runnable() {         public void run() {             looper.prepare();             log.w("gps tracker", "tracker going run "+new date());             locationmanager mlocmanager =(locationmanager)getsystemservice(context.location_service);             locationlistener mloclistener = new mylocationlistener();             mlocmanager.requestlocationupdates( locationmanager.gps_provider, 0, 0, mloclistener);//, looper.getmainlooper());              mtimer1.postdelayed(this, interval1 * 1000l);             looper.loop();          }     };   //=============================================================================================================================     private handler mtimer2 = new handler();     private runnable mtask2 = new runnable() {         public void run() {             if (isonline() == true) {                 log.w("method 2", "setupdatecardaccepttag");                 setupdatecardaccepttag();                 log.w("method 3", "getcardbulkserialdata");                 getcardbulkserialdata();                 log.w("method 12", "updatestockdatafromremote");                 updatestockdatafromremote();                 log.w("method 5", "setremarksdata");                 setremarksdata();                 log.w("method 6", "setcardsaledata");                 setcardsaledata();                 log.w("method 7", "synchmerchants");                 synchmerchants();                 log.w("method 9", "getupdatedcities");                 getupdatedcities();                 log.w("method 10", "getnotifications");                 getnotifications();                 log.w("method 11", "getnextserialdetails");                 getnextserialdetails();                 log.w("method 12", "getnextserialdetails");                 //synchlocations();                 log.w("method 13", "synchlocations");              }             mtimer2.postdelayed(this, interval2 * 1000l);         }     }; 

when run application stopped after few seconds.its says below error message in log console please me sort out issue

thanks

you can not prepare looper multiple times thread. before preparing, chcek whether looper associated thread or not.

private runnable mtask1 = new runnable() {     public void run() {         if(looper.mylooper() == null) { // check looper associated or not.            looper.prepare(); // no looper defined define new 1         }         log.w("gps tracker", "tracker going run "+new date());         locationmanager mlocmanager =(locationmanager)getsystemservice(context.location_service);         locationlistener mloclistener = new mylocationlistener();         mlocmanager.requestlocationupdates( locationmanager.gps_provider, 0, 0, mloclistener);//, looper.getmainlooper());          mtimer1.postdelayed(this, interval1 * 1000l);         looper.loop();      } }; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -