Back to project page android-job-queue-exemple.
The source code is released under:
GNU General Public License
If you think the Android project android-job-queue-exemple listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.testpathlib.jobs; /* w w w.java 2s .c om*/ import com.example.testpathlib.Utils; import com.example.testpathlib.events.Event; import com.path.android.jobqueue.BaseJob; import java.util.concurrent.atomic.AtomicInteger; import de.greenrobot.event.EventBus; /** * Created by Julien Quivreux on 23/12/13. */ public class GetDataJob extends BaseJob { private static final AtomicInteger jobCounter = new AtomicInteger(0); private static boolean requiresNetwork = false; private static boolean persistent = false; private static String groupId = "get-data"; private final int id; public GetDataJob() { super(requiresNetwork, persistent, groupId); id = jobCounter.incrementAndGet(); } @Override public void onAdded() { } @Override public void onRun() throws Throwable { /** * regarde si d'autre requte similaire on t ajout aprs celle-ci. * Il n'y a pas de raison de tlcharger de multiple fois les donnes, * donc si c'est le cas on coupe le traitement doublon */ if (id != jobCounter.get()) { return; } Thread.sleep(2*1000);//simulate work String result= Utils.GetHTML("www.google.fr", null); EventBus.getDefault().post(new Event.TextDataReceived(result)); } @Override protected void onCancel() { EventBus.getDefault().post(new Event.TextDataReceived("Action stopp")); } @Override protected boolean shouldReRunOnThrowable(Throwable throwable) { EventBus.getDefault().post(new Event.ErrorTextDataReceived("internet absent")); return false; } }