android - Update userpositon to server periodically using Endpoints -
i update users position google endpoint in google app engine periodically.
fact i'm using endpoints important, because that's why cant use intentservice
, alarmmanger
schedule task.
the problem following:
update position server need objects not accessible in service.
let me try sketch it:
public class myservice extends intentservice { [...] @override public int onstartcommand(intent intent, int flags, int startid) { endpointshandler.updateposition() return super.onstartcommand(intent, flags, startid); } }
here need objects of endpointshandler
. cannot create new object, because depends on other objects googleapiclient
.
but cannot add objects server because when initialize alarmmanager
there no way pass objects
alarmmanager alarmmanager = (alarmmanager) getsystemservice(alarm_service); intent updaterintent = new intent(this, myservice.class); pendingintent pendingintent = pendingintent.getservice(this, 0, updaterintent, 0); alarmmanager.setrepeating(alarmmanager.elapsed_realtime_wakeup, some_period, some_period, pendingintent);
i pass objects in intent, besides fact classes (even googleapiclient
) have implement parceable
, don't thing way. i'm sure there clean way not able find.
i solved on own.
since didn't find solution on so, i'll post here:
i used way descriped here. created central controller-class keeps important objects of app. class subclass of android.app.application
.
in manifest-file added
<application [...] android:name=".controllers.appcontroller">
to declare use custom application class.
in each activity , service can use getapplication()
object of application-class.
Comments
Post a Comment