google navigation intent kills the background service android -


background service stopped after time due google navigation intent open. background service using gps tracking. code as

public class longbackgroundintentservice extends intentservice {     private static final string tag = "map";     windowmanager windowmanager;     imageview back;     windowmanager.layoutparams params;     private locationlistener locationlistener;     private locationmanager locationmanager;     private context context;     public static final long min_time_bw_updates = 1500; // sec     public static final long min_distance_change_for_updates = 10; // meters      public longbackgroundintentservice() {         super(null);     }      public longbackgroundintentservice(string name) {         super(name);         //setintentredelivert(true);     }      @override     public void oncreate() {         super.oncreate();          context = this;         devicegpslocation();         windowmanager = (windowmanager) getsystemservice(window_service);          = new imageview(this);         back.setimageresource(r.mipmap.ic_launcher);          params = new windowmanager.layoutparams(                 150,                 150,                 windowmanager.layoutparams.type_phone,                 windowmanager.layoutparams.flag_not_focusable, pixelformat.translucent);         params.gravity = gravity.bottom | gravity.right;         params.x = 10;         params.y = 200;          windowmanager.addview(back, params);         back.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 try {                     log.d(tag, " close navigation onclick() stop running");                     if (windowmanager != null) windowmanager.removeview(back);                     //stopself();                     //stopservice(new intent(getapplicationcontext(),longbackgroundservice.class));                     //stopservice(new intent(getapplicationcontext(),longbackgroundintentservice.class));                     alarmmanager mgr = (alarmmanager) getapplicationcontext().getsystemservice(context.alarm_service);                     intent = new intent(getapplicationcontext(), longbackgroundintentservice.class);                     i.putextra("stop","stop");                     pendingintent pi = pendingintent.getservice(getapplicationcontext(), 0, i, 0);                     mgr.cancel(pi);                     // resume app                     intent intent = new intent(longbackgroundintentservice.this, mapsactivity.class);                     intent.addflags(intent.flag_activity_clear_top);                     intent.addflags(intent.flag_activity_single_top);                     intent.addflags(intent.flag_activity_no_history);                     intent.addflags(intent.flag_from_background);                     intent.addflags(intent.flag_activity_new_task);                     longbackgroundintentservice.this.startactivity(intent);                 } catch (exception e) {                     e.printstacktrace();                 }             }         });     }      @override     protected void onhandleintent(intent intent) {               long ct = system.currenttimemillis();             alarmmanager mgr = (alarmmanager) getapplicationcontext().getsystemservice(context.alarm_service);             intent = new intent(getapplicationcontext(), longbackgroundintentservice.class);             i.putextra("stop","nostop");             pendingintent pi = pendingintent.getservice(getapplicationcontext(), 0, i, 0);             mgr.set(alarmmanager.rtc_wakeup, ct + 30000, pi);             //stopself(); //stop service since no longer needed , new alarm set       }      private void devicegpslocation() {         calllocationlistener(); // sets current lat & lng         // gives current location position         locationmanager = (locationmanager) context.getsystemservice(context.location_service);          if (activitycompat.checkselfpermission(this, manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(this, manifest.permission.access_coarse_location) != packagemanager.permission_granted) {             // todo: consider calling             //    activitycompat#requestpermissions             // here request missing permissions, , overriding             //   public void onrequestpermissionsresult(int requestcode, string[] permissions,             //                                          int[] grantresults)             // handle case user grants permission. see documentation             // activitycompat#requestpermissions more details.             return;         }         locationmanager.requestlocationupdates(                 locationmanager.gps_provider,                 min_time_bw_updates,                 min_distance_change_for_updates,                 locationlistener);         locationmanager.requestlocationupdates(                 locationmanager.network_provider,                 min_time_bw_updates,                min_distance_change_for_updates,                 locationlistener);     }      // keep method     public int checkselfpermission(string accessfinelocation) {         return packagemanager.permission_granted;     }      private void calllocationlistener() {         // using calculate trip distance , speed         locationlistener = new locationlistener() {             @override             public void onlocationchanged(location location) {                 log.d(tag, "lat & lng " + location.getlatitude() + " " + location.getlongitude());             }              @override             public void onstatuschanged(string provider, int status, bundle extras) {              }              @override             public void onproviderenabled(string provider) {              }              @override             public void onproviderdisabled(string provider) {                   intent intent = new intent(settings.action_location_source_settings);                   startactivity(intent);             }         };     } } 

during run after time service stopped know service used long running background operation amazed effected during run google app navigation intent. solution this?.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -