Skip to content

Instantly share code, notes, and snippets.

Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
ComponentName service = new ComponentName(this, MyJobService.class);
JobScheduler mJobScheduler = (JobScheduler)getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder builder = new JobInfo.Builder(jobId, serviceComponent)
.setRequiredNetworkType(jobInfoNetworkType)
.setRequiresCharging(false)
.setRequiresDeviceIdle(false)
.setExtras(extras).build();
mJobScheduler.schedule(jobInfo);
int threads = Runtime.getRuntime().availableProcessors();
ExecutorService executor = Executors.newFixedThreadPool(threads);
executor.submit(myWork);
public class NetworkHttpUnauthorizedReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
int httpCode = intent.getIntExtra(IntentExtras.HTTP_CODE, -1);
if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
LoginActivity.logOut(context);
}
}
}
<receiver
android:name=".login.NetworkHttpUnauthorizedReceiver">
<intent-filter>
<action android:name="com.startup.network.http_unauthorized"/>
</intent-filter>
</receiver>
public class MyIntentService extends IntentService {
private static final String TAG = MyIntentService.class.getSimpleName();
private ArrayList<Object> objects;
private long timeMillisInBackground;
public MyIntentService() {
super("MyIntentService");
}
@Override protected void onHandleIntent(Intent intent) {
public class MyService extends Service {
private static final String TAG = MyService.class.getSimpleName();
private ArrayList<Object> objects;
public MyService() {
}
@Override public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
public class StarWarsService extends IntentService {
public StarWarsService() {
super("StarWarsService");
}
@Override protected void onHandleIntent(Intent intent) {
if (intent != null) {
String json = ResourcesUtil.loadJson(this);
Gson gson = new GsonBuilder().setDateFormat("MMM d, yyyy").create();
ArrayList<StarWarsMovie> moviesList =
public class MainPresenter extends BasePresenter<MainActivityView> {
public static final String LOAD_COMPLETE_ACTION =
"com.academy.android.starwarsmovies.load_complete";
public static final String DATA_KEY = "data_key";
private StarWarsMovieDataReceiver movieDataReceiver;
private ArrayList<StarWarsMovie> movieList;
@Override public void attachView(MainActivityView mainActivityView) {
super.attachView(mainActivityView);
registerLoadDataReceiver();
public abstract class BasePresenter<T extends MvpView> {
HandlerThread thread;
Looper looper;
Handler handler;
private T mView;
public BasePresenter() {
}