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:

  1. there wrong google play services
  2. you prompted user dialog returned googleplayservicesutil.geterrordialog() fix error
  3. user changed settings/etc. using activity
  4. 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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -