google play services - Android creating geofence -
i working on geofence api launched in google i/o 2013. creating , monitoring geofences
there method in example given in above link follows:
public void creategeofences() { ........ mgeofencelist.add(muigeofence1.togeofence()); mgeofencelist.add(muigeofence2.togeofence()); }
this method inside onactivityresult of activity , in same activity have button save geofence , call mlocationclient.connect() -> it's same addgeofences() method of example.
@override private void onconnected(bundle databundle) { ... switch (mrequesttype) { case add : // pendingintent request mtransitionpendingintent = gettransitionpendingintent(); // send request add current geofences mlocationclient.addgeofences( mgeofencelist, pendingintent, this); ... } }
in method mgeofencelist empty should not since has been updated in onactivityresult method before.
problem: variable mgeofencelist updated in onactivityresult when accessed in onconnected method empty. wrong? please help.
are sure understand when/whether onactivityresult
called? onactivityresult
called result of previous call of startactivityforresult
, not mentioning.
although, in case, usage of method bit more clever. quote tutorial provided:
if encounter error, call googleplayservicesutil.geterrordialog() retrieve localized dialog prompts users take correct action, display dialog in dialogfragment. dialog may allow user correct problem, in case google play services may send result activity. handle result, override method onactivityresult().
so, if using code tutorial, onactivityresult
called when:
- there wrong google play services
- you prompted user dialog returned
googleplayservicesutil.geterrordialog()
fix error - user changed settings/etc. using activity
- the activity returned resultcode
since running google play services without problems, onactivityresult
never called, , therefore list empty.
i suggest moving creategeofences()
oncreate
(if testing , not have lot of them) or background thread (if have them lot or no not want slow down activity start)
Comments
Post a Comment