firebase jobdispatcher

0
public class MyJobService  extends JobService {

    BackgroundTask backgroundTask;
    @Override
    public boolean onStartJob(JobParameters job) {
        backgroundTask = new BackgroundTask()
        {
          @Override
          protected void onPostExecute(String s)
          {
              //System.out.println("on Post Execute");
              Toast.makeText(getApplicationContext(),"Message from Background task: "+ s,Toast.LENGTH_LONG).show();
              jobFinished(job,false);
          }
        };
        backgroundTask.execute();
        return false; // Answers the question: "Is there still work going on?"
    }

    @Override
    public boolean onStopJob(JobParameters job) {
        return true; // Answers the question: "Should this job be retried?"
    }

    public static class BackgroundTask extends AsyncTask<Void,Void,String>
    {
        @Override
        protected Void doInBacground(Void... voids)
        {
            return null;
        }
    }

}

lista errorów:
error: MyJobService is not abstract and does not override abstract method onStopJob(JobParameters) in JobService
error: method does not override or implement a method from a supertype (on startjob)
error: BackgroundTask is not abstract and does not override abstract method doInBackground(Void...) in AsyncTask
error: method does not override or implement a method from a supertype (Backgroundtask)
error: incompatible types: android.app.job.JobParameters cannot be converted to com.firebase.jobdispatcher.JobParameters
error: method does not override or implement a method from a supertype (onstopjob)

nie wiem co jest grane,

wpis w build.gradle(module:app) jest:

implementation 'com.firebase:firebase-jobdispatcher:0.8.5'

w android manifest również:

          <service
            android:name=".MyJobService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE" />
            </intent-filter>
        </service>

nie wiem co jest nie tak i jak to naprawić

0

Masz dokładnie napisane w wiadomościach błędów, co jest źle. Naucz się korzystać z IDE.

W BackgroundTask masz złą sygnaturę metody i lietrówkę w jej nazwie. W MyJobService importujesz android.app.job.JobParameters zamiast com.firebase.jobdispatcher.JobParameters.

0

poprawiłem kod, ale jest taki problem, że proces nie działa po zminimalizowaniu aplikacji

public class MyActivity extends AppCompatActivity {


    private static final String JOB_TAG="my_job_tag";
    private FirebaseJobDispatcher jobDispatcher;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_myactivity);


        jobDispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
        Job job = jobDispatcher.newJobBuilder().
                setService(PassiveIncomeJobService.class).
                setLifetime(Lifetime.FOREVER).
                setTag(JOB_TAG).
                setRecurring(true).
                setTrigger(Trigger.executionWindow(0,25)).
                setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL).
                setReplaceCurrent(false).
                build();
        jobDispatcher.mustSchedule(job);

    }
     

}
0

Jeżeli ma działać po minimalizacji to zrób serwis:
https://developer.android.com/guide/components/services

0

Przecież właśnie tam jest service, rozszerzający JobService i to wystarczy. Autor nawet nie umie przekopiować przykładowego kodu z Githuba, gdzie wszystko jest czarno na białym pokazane. Sam z tego korzystałem i działa to zawsze, nawet po minimalizacji a nawet po restarcie telefonu.

Pewnie problem jest w tym, że serwis nie jest prawidłowo dodany do AndroidManifest albo nie zostały przydzielone odpowiednie uprawnienia

1 użytkowników online, w tym zalogowanych: 0, gości: 1