16. GPS Provider Cell Network Provider
More Accurate
More Power
Less Accurate
Less Power
17. Better Accuracy Better Battery
PRIORITY_HIGH_ACCURACY
PRIORITY_BALANCED_POWER_ACCURACY PRIORITY_LOW_POWER
PRIORITY_NO_POWER
What’s the best State for
right now?
34. JobInfo uploadJob =
new JobInfo.Buildr(mSomeInt, mServiceComponent)
.setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED)
.setOverrideDeadline(DateUtils.HOUR_IN_MILLIS)
.setRequiresCharging(true)
.build();
JobScheduler API
35. JobInfo uploadJob =
new JobInfo.Buildr(mSomeInt, mServiceComponent)
.setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED)
.setOverrideDeadline(DateUtils.HOUR_IN_MILLIS)
.setRequiresCharging(true)
.build();
JobScheduler API
JobId
36. JobInfo uploadJob =
new JobInfo.Buildr(mSomeInt, mServiceComponent)
.setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED)
.setOverrideDeadline(DateUtils.HOUR_IN_MILLIS)
.setRequiresCharging(true)
.build();
JobScheduler API
Job Endpoint
37. JobInfo uploadJob =
new JobInfo.Buildr(mSomeInt, mServiceComponent)
.setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED)
.setOverrideDeadline(DateUtils.HOUR_IN_MILLIS)
.setRequiresCharging(true)
.build();
JobScheduler API
Network Type
38. JobInfo uploadJob =
new JobInfo.Buildr(mSomeInt, mServiceComponent)
.setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED)
.setOverrideDeadline(DateUtils.HOUR_IN_MILLIS)
.setRequiresCharging(true)
.build();
JobScheduler API
Timing Constraint
39. JobInfo uploadJob =
new JobInfo.Buildr(mSomeInt, mServiceComponent)
.setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED)
.setOverrideDeadline(DateUtils.HOUR_IN_MILLIS)
.setRequiresCharging(true)
.build();
JobScheduler API
Extra Constraint
42. // Schedule a task to occur between five and fifteen minutes from now:
OneoffTask myTask = new OneoffTask.Builder()
.setService(MyGcmTaskService.class)
.setExecutionWindow(
5 * DateUtil.MINUTE_IN_SECONDS, 15 * DateUtil.MINUTE_IN_SECONDS)
.setTag("test-upload")
.build();
GcmNetworkManager.get(this).schedule(myTask);
GcmNetworkManager
GcmNetworkManager
https://goo.gl/hTwIEt
43. // Implement service logic to be notified when the task elapses:
MyUploadService extends GcmTaskService {
@Override
public int onRunTask(TaskParams params) {
// Do some upload work.
return GcmNetworkManager.RESULT_SUCCESS;
}
}
GcmNetworkManager
GcmNetworkManager
https://goo.gl/hTwIEt
44. // Implement service logic to be notified when the task elapses:
MyUploadService extends GcmTaskService {
@Override
public int onRunTask(TaskParams params) {
// Do some upload work.
return GcmNetworkManager.RESULT_SUCCESS;
}
}
GcmNetworkManager
adb shell am broadcast -a "com.google.android.gms.gcm.ACTION_TRIGGER_TASK"
-e component -e tag
GcmNetworkManager
https://goo.gl/hTwIEt
86. // Primitive version
int total = 0;
for (int i = 0; i < 100; i++)
total += i;
// Generic version
Integer total = 0;
for (int i = 0; i < 100; i++)
total += i;
87. // Primitive version
int total = 0;
for (int i = 0; i < 100; i++)
total += i;
// Generic version
Integer total = 0;
for (int i = 0; i < 100; i++)
//total += i;
Allocates 83 new objects!
(yea, i know, it’s confusing..)
Allocates 0 new objects!
// create new Integer(),
// push in new value
// add to total
96. public static final int VALUE1 = 1;
public static final int VALUE2 = 2;
public static final int VALUE3 = 3;
int func(int value) {
switch (value) {
case VALUE1:
return -1;
case VALUE2:
return -2;
case VALUE3:
return -3;
}
return 0;
}
Bytes
2680
+124 bytes
97. public static enum Value {
VALUE1,
VALUE2,
VALUE3
}
int func(Value value) {
switch (value) {
case VALUE1:
return -1;
case VALUE2:
return -2;
case VALUE3:
return -3;
}
return 0;
} Bytes
4188
13x more
than int version
98. public static enum Value {
VALUE1,
VALUE2,
VALUE3
}
12-16 bytes
for the array
20+ bytes (each)