android - How to keep GoogleAPIClient always connected -


i using googleapiclient read location information. want connected. how ensure connected. 1 way reconnect whenever connection failure callbacks invoked.

what use-case @ below callbacks triggered? 1.onconnectionfailedlistener -> onconnectionfailed 2. connectioncallbacks -> onconnectionsuspended

i tried force stopping google play services did not callback [onconnectionsuspended]

will there issue (battery, performance) if googleapiclient connected?

from official documentation can find following:

// create instance of googleapiclient. if (mgoogleapiclient == null) {      mgoogleapiclient = new googleapiclient.builder(this)          .addconnectioncallbacks(mconnectioncallbacks)          .addonconnectionfailedlistener(mconnectionfailedcallbacks)          .addapi(locationservices.api)          .build(); } //you need specify callbacks.  //of course, need connected: protected void onstart() {      mgoogleapiclient.connect();      super.onstart(); }  //disconnect protected void onstop() {      mgoogleapiclient.disconnect();      super.onstop(); }  //get last location public location getlastlocation(){ //you need connected. therefore must in onconnected //method of mconnectioncallbacks.      mlastlocation = locationservices.fusedlocationapi.getlastlocation(             mgoogleapiclient); } 

link: getting last known location

edit:
use case having connected (or know) when want have service tracks location when app in background.
read here interesting tutorials this:
http://www.101apps.co.za/articles/services-tutorials-part-2-a-foreground-service.html
http://www.edureka.co/blog/android-tutorials-beginners-service-component/
edit 2
links details failed connection:
1. onconnectionfailed
2. accessing google api


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -