This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<receiver | |
android:name=".login.NetworkHttpUnauthorizedReceiver"> | |
<intent-filter> | |
<action android:name="com.startup.network.http_unauthorized"/> | |
</intent-filter> | |
</receiver> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int threads = Runtime.getRuntime().availableProcessors(); | |
ExecutorService executor = Executors.newFixedThreadPool(threads); | |
executor.submit(myWork); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Job myJob = firebaseJobDispatcher.newJobBuilder() | |
.setService(SmartService.class) | |
.setTag(SmartService.LOCATION_SMART_JOB) | |
.setReplaceCurrent(false) | |
.setConstraints(ON_ANY_NETWORK) | |
.build(); | |
firebaseJobDispatcher.mustSchedule(myJob); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocationUploadWorker extends Worker { | |
@Override | |
public WorkerResult doWork() { | |
Location location = LocationRepository.getLastLocation(); | |
ServerReport serverReport = new ServerReport(location); | |
FirebaseDatabase database = FirebaseDatabase.getInstance(); | |
DatabaseReference myRef = | |
database.getReference("WorkerReport v" + android.os.Build.VERSION.SDK_INT); | |
myRef.push().setValue(serverReport); | |
return WorkerResult.SUCCESS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create constraints | |
Constraints constraints = new Constraints.Builder().setRequiredNetworkType | |
(NetworkType.CONNECTED).build(); | |
//create work | |
Work uploadWork = new Work.Builder(LocationUploadWorker.class).withConstraints | |
(constraints).build(); | |
//schedule work | |
WorkManager.getInstance(this).enqueue(uploadWork); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WorkManager.getInstance(context).getStatusById(work.getId()) | |
.observe(lifecycleOwner, status -> { | |
// Do something with the status | |
if (status != null && status.getState().isFinished()) { … } | |
}); |