-3
  1. How can i send location to server even when application closes
  2. Is there any code please share with me.
  3. Thanks in advance

1 Answers1

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