I am new to android programming. I am planning to make an app that is location sensitive.
I am trying to use Google Play Services' Location Based APIs to detect the user's current location. For this I have been following the sample code and the details given here :-
developer.android.com- detect user's current location- Location APIs- Google Play Services
I am trying to understand the connection between the different method calls involved in detecting a user's current location. Now the above link although seems to have a lot of information, being a newbie, I find it difficult to connect the different method calls here.
So roughly what I understand form the code in the above URL is this :-
- In the onCreate() of the MainActivity class we create a LocationClient. LocationClient is used to connect to the location services.
- Now in the onStart() inside the MainActivity Class, we call locationClientObjet.connect().So it means that whenever the MainActivity of the app becomes visible, an attempt to connect to the location services is made.
- Now before we even made the LocationClient we had already defined something known as the Location Services CallBacks.
- So we implement the required interfaces and define the respective methods. So for example, the onConnected() gets called when the request to connect the client finishes successfully.
Now so far everything sounds good. The problem arises when I try to connect the above part with the below mentioned :-
- Now before even we had defined the Location Services CallBacks, we had defined an inner class inside the MainActivity class called, ErrorDialogFragment. This class is I guess used to create an error fragment (like an alert box) that can display error messages to the user in case apparently the connection attempt to the Location Services fails due to some reason. So there are some things that I do not understand here :-
- What is the use of CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000; The documentation in the page says :- Define a request code to send to Google Play services. This code is returned in Activity.onActivityResult. I do not understand this.
- When is the onCreateDialog() inside the ErrorDialogFragment class get called. I do not find an explicit call to this method anywhere in the sample code mentioned on the page in the URL mentioned above.
- What is the connection between the onConnectionFailed() and the error fragment.
- There are 2 more methods defined :- onActivityResult() and servicesConnected(). I understand to some extent the use of servicesConnected() - it is used to see if the GooglePlay services is available. Is it a user defined method ? And is it not ding the same things that were being done inside the callback methods onConnected(), onDisConnected() and onConnectionFailed(). If not how are they different from servicesConnected() ?
- And finally I just do not understand what is the use of onActivityResult(), what exactly are we trying to do here ?
Please pardon my ignorance. I am completely new to Android Programming and am trying to learn concepts clear and sound. Please correct me wherever I went wrong or misunderstood things. I tried looking through Vogella resources but could not find much help. Any good resources explaining details that would make my above concepts clear would be great help.