- How can i send location to server even when application closes
- Is there any code please share with me.
- Thanks in advance
Asked
Active
Viewed 49 times
-3

nagaraj nagu
- 1
- 2
1 Answers
0
We can not directly provide you code because of your knowledge, We suggest you step or some code snap which guides you.
. Implement firebase Job Dispatcher Firebase JobDispatcher
. After successful adding library creates one service which extending JobService like bellow.
import com.firebase.jobdispatcher.JobParameters;
import com.firebase.jobdispatcher.JobService;
public class MyJobService extends JobService {
@Override
public boolean onStartJob(JobParameters job) {
// Do some work here
//getLatestLocationAndUpdateOnserver()
//Don't miss to reschedule job
return false; // Answers the question:z "Is there still work going on?"
}
@Override
public boolean onStopJob(JobParameters job) {
return false; // Answers the question: "Should this job be retried?"
}
}
. Finally, Schedule Job-like bellow
private void scheduleJob() {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Bundle myExtrasBundle = new Bundle();
myExtrasBundle.putString("request_sender", "Data Want to add");
com.firebase.jobdispatcher.Job myJob = dispatcher.newJobBuilder()
.setService(MyJobService.class) // the JobService that will be called
.setTag("my-unique-tag")
.setTrigger(Trigger.executionWindow(600, 610)) //this will fire after 10minute
.setReplaceCurrent(true)// uniquely identifies the job
.setExtras(myExtrasBundle)
.build();
if (dispatcher != null) {
dispatcher.cancel("my-unique-tag");
}
dispatcher.mustSchedule(myJob);
}

Dhaval Solanki
- 4,589
- 1
- 23
- 39
-
Thanks for your reply.If there is any other possible code please suggest me. – nagaraj nagu May 30 '18 at 04:19
-
I suggest JobSchedular because after Orea android not directly support to run service using startService(). – Dhaval Solanki May 30 '18 at 04:28