SlideShare a Scribd company logo
Yonatan V.Levin levin.yonatan
parahallGoogle Developer Expert
>100 Cities > 30M usersRuby, Go, Python, Microservices
Ooooops...
Making genetic tests
accessible
~ 2900 members Largest Android Active Community
What Do We Do?
● Android Fundamentals
● Android UI / UX
● Community Hackathon
● Android Performance
● Mentors Program
● Active community
VOTE HERE:
https://goo.gl/tsmeK2
Saving galaxy with 1% of battery
Wild Wild West
It’s endless way to screw things
public class GettLocationService extends Service implements
Handler.Callback
public void onCreate() {
handlerThread = new HandlerThread("RebelServiceHandlerThread");
handlerThread.start();
Looper looper = handlerThread.getLooper();
handler = new Handler(looper, this);
handler.sendEmptyMessage(WHAT_MAKE_NETWORK_REQUEST);
}
My $0.02
Main
Activity
Naive
Service
HandlerThread
Looper
Location
Handler
Network
Handler
Broadcast
Receiver
Location
Tracker
BOOT_COMPLETED
Receiver
AlarmManager
Every 5 min
@Override public void onCreate() {
super.onCreate();
handlerThread = new HandlerThread("MyHandlerThread");
handlerThread.start();
looper = handlerThread.getLooper();
locationHandler = new LocationHandler(looper, getApplicationContext());
mReceiver = new NaiveBroadcastReceiver();
mNaiveNetworkHandler = new NetworkHandler(looper);
}
public class NaiveService extends Service {
@Override public void onCreate() {
super.onCreate();
handlerThread = new HandlerThread("MyHandlerThread");
handlerThread.start();
looper = handlerThread.getLooper();
locationHandler = new LocationHandler(looper, getApplicationContext());
mReceiver = new NaiveBroadcastReceiver();
mNaiveNetworkHandler = new NetworkHandler(looper);
}
public class NaiveService extends Service {
@Override public void onCreate() {
super.onCreate();
handlerThread = new HandlerThread("MyHandlerThread");
handlerThread.start();
looper = handlerThread.getLooper();
locationHandler = new LocationHandler(looper, getApplicationContext());
mNaiveNetworkHandler = new NetworkHandler(looper);
mReceiver = new NaiveBroadcastReceiver();
}
public class NaiveService extends Service {
@Override public void onCreate() {
super.onCreate();
handlerThread = new HandlerThread("MyHandlerThread");
handlerThread.start();
looper = handlerThread.getLooper();
locationHandler = new LocationHandler(looper, getApplicationContext());
mNaiveNetworkHandler = new NetworkHandler(looper);
mReceiver = new NaiveBroadcastReceiver();
}
public class NaiveService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
LocalBroadcastManager.getInstance(this)
.registerReceiver(mReceiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST);
locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST);
return super.onStartCommand(intent, flags, startId);
}
public class NaiveService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
LocalBroadcastManager.getInstance(this)
.registerReceiver(mReceiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST);
locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST);
return super.onStartCommand(intent, flags, startId);
}
public class NaiveService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
LocalBroadcastManager.getInstance(this)
.registerReceiver(mReceiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST);
locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST);
return super.onStartCommand(intent, flags, startId);
}
public class NaiveService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
LocalBroadcastManager.getInstance(this)
.registerReceiver(mReceiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST);
locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST);
return super.onStartCommand(intent, flags, startId);
}
public class NaiveService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
LocalBroadcastManager.getInstance(this)
.registerReceiver(mReceiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST);
locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST);
return super.onStartCommand(intent, flags, startId);
}
public class NaiveService extends Service {
@Override public void onDestroy() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
locationHandler.removeCallbacksAndMessages(null);
mNaiveNetworkHandler.removeCallbacksAndMessages(null);
locationHandler.stop();
locationHandler = null;
mNaiveNetworkHandler = null;
looper.quit();
handlerThread.quit();
locationHandler = null;
}
public class NaiveService extends Service {
public class LocationHandler extends Handler {
LocationHandler(Looper looper, Context context) {
super(looper);
locationTracker = new LocationTracker(context, getLooper());
}
public void handleMessage(Message msg) {
switch (msg.what) {
case WHAT_LOCATION_REQUEST:
sendEmptyMessageDelayed(WHAT_LOCATION_REQUEST, FIVE_MINUTES);
locationTracker.start();
}
}
public class LocationHandler extends Handler {
LocationHandler(Looper looper, Context context) {
super(looper);
locationTracker = new LocationTracker(context, getLooper());
}
public void handleMessage(Message msg) {
switch (msg.what) {
case WHAT_LOCATION_REQUEST:
sendEmptyMessageDelayed(WHAT_LOCATION_REQUEST, FIVE_MINUTES);
locationTracker.start();
}
}
public class LocationHandler extends Handler {
LocationHandler(Looper looper, Context context) {
super(looper);
locationTracker = new LocationTracker(context, getLooper());
}
public void handleMessage(Message msg) {
switch (msg.what) {
case WHAT_LOCATION_REQUEST:
sendEmptyMessageDelayed(WHAT_LOCATION_REQUEST, FIVE_MINUTES);
locationTracker.start();
}
}
public class LocationHandler extends Handler {
void stop() {
locationTracker.stop();
}
class LocationTracker {
mLocationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER,
mGpsLocationListener,
looper);
mLocationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER,
mNetworkLocationListener, looper);
class LocationTracker {
private void broadcastLocation(Location location) {
if (mWeakReference.get() != null) {
Intent intent = new
Intent(NaiveService.NaiveBroadcastReceiver.ACTION_NEW_LOCATION_ARRIVED);
intent.putExtra(NaiveService.NaiveBroadcastReceiver.LOCATION_KEY, location);
LocalBroadcastManager.getInstance(mWeakReference.get()).sendBroadcast(intent);
}
}
class LocationTracker {
private void broadcastLocation(Location location) {
if (mWeakReference.get() != null) {
Intent intent = new
Intent(NaiveService.NaiveBroadcastReceiver.ACTION_NEW_LOCATION_ARRIVED);
intent.putExtra(NaiveService.NaiveBroadcastReceiver.LOCATION_KEY, location);
LocalBroadcastManager.getInstance(mWeakReference.get()).sendBroadcast(intent);
}
}
class LocationTracker {
private void broadcastLocation(Location location) {
if (mWeakReference.get() != null) {
Intent intent = new
Intent(NaiveService.NaiveBroadcastReceiver.ACTION_NEW_LOCATION_ARRIVED);
intent.putExtra(NaiveService.NaiveBroadcastReceiver.LOCATION_KEY, location);
LocalBroadcastManager.getInstance(mWeakReference.get()).sendBroadcast(intent);
}
}
public class NaiveBroadcastReceiver extends LocationBaseBroadcast {
public void onReceive(Context context, Intent intent) {
Location location = intent.getExtras().getParcelable(LOCATION_KEY);
Message message =
mNaiveNetworkHandler.obtainMessage(NetworkHandler.WHAT_SEND_NAIVE_REPORT,
location);
mNaiveNetworkHandler.sendMessage(message);
}
}
public class NaiveBroadcastReceiver extends LocationBaseBroadcast {
public void onReceive(Context context, Intent intent) {
Location location = intent.getExtras().getParcelable(LOCATION_KEY);
Message message =
mNaiveNetworkHandler.obtainMessage(NetworkHandler.WHAT_SEND_NAIVE_REPORT,
location);
mNaiveNetworkHandler.sendMessage(message);
}
}
public class NaiveBroadcastReceiver extends LocationBaseBroadcast {
public void onReceive(Context context, Intent intent) {
Location location = intent.getExtras().getParcelable(LOCATION_KEY);
Message message =
mNaiveNetworkHandler.obtainMessage(NetworkHandler.WHAT_SEND_NAIVE_REPORT,
location);
mNaiveNetworkHandler.sendMessage(message);
}
}
public class NetworkHandler extends Handler {
@Override public void handleMessage(Message msg) {
switch (msg.what) {
case WHAT_SEND_NAIVE_REPORT:
Location location = (Location) msg.obj;
ServerReport serverReport = new ServerReport(location);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("NaiveReport");
myRef.push().setValue(serverReport);
Break;
}
}
public class NetworkHandler extends Handler {
@Override public void handleMessage(Message msg) {
switch (msg.what) {
case WHAT_SEND_NAIVE_REPORT:
Location location = (Location) msg.obj;
ServerReport serverReport = new ServerReport(location);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("NaiveReport");
myRef.push().setValue(serverReport);
Break;
}
}
public class NetworkHandler extends Handler {
@Override public void handleMessage(Message msg) {
switch (msg.what) {
case WHAT_SEND_NAIVE_REPORT:
Location location = (Location) msg.obj;
ServerReport serverReport = new ServerReport(location);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("NaiveReport");
myRef.push().setValue(serverReport);
Break;
}
}
public class NetworkHandler extends Handler {
@Override public void handleMessage(Message msg) {
switch (msg.what) {
case WHAT_SEND_NAIVE_REPORT:
Location location = (Location) msg.obj;
ServerReport serverReport = new ServerReport(location);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("NaiveReport");
myRef.push().setValue(serverReport);
Break;
}
}
GPS Points
192
locations
WakeLock
startService();
<receiver android:name=".MyBroadcastReceiver"
android:permission="android.permission.SEND_SMS">
<intent-filter>
<action android:name="android.intent.action.AIRPLANE_MODE"/>
</intent-filter>
</receiver>
Few times in an hour
Aug 2018:
targetSDKVersion >= 26
JobScheduler for the rescue
Main
Activity
SmartService
Service
HandlerThread
Looper
Location
Handler
Network
Handler
Broadcast
Receiver
Location
Tracker
Every 5 min
JobScheduler
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class SmartService extends JobService {
public static final String LOCATION_SMART_JOB = "LOCATION_SMART_JOB";
public class SmartService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
LocalBroadcastManager.getInstance(this).registerReceiver(receiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationTracker.start();
return true;
}
public boolean onStopJob(JobParameters jobParameters) {
locationTracker.stop();
return true;
}
public class SmartService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
LocalBroadcastManager.getInstance(this).registerReceiver(receiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationTracker.start();
return true;
}
public boolean onStopJob(JobParameters jobParameters) {
locationTracker.stop();
return true;
}
public class SmartService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
LocalBroadcastManager.getInstance(this).registerReceiver(receiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationTracker.start();
return true;
}
public boolean onStopJob(JobParameters jobParameters) {
locationTracker.stop();
return true;
}
public class SmartService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
LocalBroadcastManager.getInstance(this).registerReceiver(receiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationTracker.start();
return true;
}
public boolean onStopJob(JobParameters jobParameters) {
locationTracker.stop();
return true;
}
public class SmartService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
LocalBroadcastManager.getInstance(this).registerReceiver(receiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationTracker.start();
return true;
}
public boolean onStopJob(JobParameters jobParameters) {
locationTracker.stop();
return true;
}
public class SmartService extends JobService {
public boolean onStartJob(JobParameters jobParameters) {
LocalBroadcastManager.getInstance(this).registerReceiver(receiver,
new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED));
locationTracker.start();
return true;
}
public boolean onStopJob(JobParameters jobParameters) {
locationTracker.stop();
return true;
}
39
locations
Same
Is it so good? :)
public class MainActivity extends AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startService(new Intent(this, MyService.class));
startService(new Intent(this, MyIntentService.class));
}
public class MyService extends Service {
@Override public int onStartCommand(Intent intent, int flags, int startId) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
final PowerManager.WakeLock wakeLock =
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
//...
}
public class MyService extends Service {
@Override public int onStartCommand(Intent intent, int flags, int startId) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
final PowerManager.WakeLock wakeLock =
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
//...
}
public class MyService extends Service {
@Override public int onStartCommand(Intent intent, int flags, int startId) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
final PowerManager.WakeLock wakeLock =
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
//...
}
public class MyService extends Service {
Thread thread = new Thread(new Runnable() {
@Override public void run() {
wakeLock.acquire();
while(true){
try {
Thread.sleep(1000L);
} catch (InterruptedException e) { e.printStackTrace(); }
}
}
});
public class MyService extends Service {
Thread thread = new Thread(new Runnable() {
@Override public void run() {
wakeLock.acquire();
while(true){
try {
Thread.sleep(1000L);
} catch (InterruptedException e) { e.printStackTrace(); }
}
}
});
public class MyService extends Service {
Thread thread = new Thread(new Runnable() {
@Override public void run() {
wakeLock.acquire();
while(true){
try {
Thread.sleep(1000L);
} catch (InterruptedException e) { e.printStackTrace(); }
}
}
});
public class MyService extends Service {
//...
thread.start();
return super.onStartCommand(intent, flags, startId);
}
Will it blend?
1. After a some time service will die, wakelock will be released,
thread will be parked
2. Service will die, wakelock will be never released, thread will run
till process will be killed
3. Service will continue to run till it stopped
4. Service will die, system will release wakelock and after some time
thread will be parked
Will it blend?
1. After a some time service will die, wakelock will be released,
thread will be parked
2. Service will die, wakelock will be never released, thread will run
till process will be killed
3. Service will continue to run till it stopped
4. Service will die, system will release wakelock and after some time
thread will be parked
Will it blend?
1. After a some time service will die, wakelock will be released,
thread will be parked
2. Service will die, wakelock will be never released, thread will run
till process will be killed
3. Service will continue to run endless
4. Service will die, system will release wakelock and after some time
thread will be parked
Will it blend?
1. After a some time service will die, wakelock will be released,
thread will be parked
2. Service will die, wakelock will be never released, thread will run
till process will be killed
3. Service will continue to run endless
4. After a some time service will die, wakelock will be released,
thread will be terminated
Will it blend?
1. After a some time service will die, wakelock will be released,
thread will be parked
2. Service will die, wakelock will be never released, thread will run
till process will be killed
3. Service will continue to run endless
4. After a some time service will die, wakelock will be released,
thread will be terminated
ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes)
All known processes:
*APP* UID 10084 ProcessRecord{f5cc46d 3558:academy.android.diveinback/u0a84}
user #0 uid=10084 gids={50084, 20084, 9997}
requiredAbi=x86 instructionSet=null
class=academy.android.diveinback.MyApp
dir=/data/app/academy.android.diveinback-ks7V4YegT65dnRcooFAcwA==/base.apk
publicDir=/data/app/academy.android.diveinback-ks7V4YegT65dnRcooFAcwA==/base.apk
data=/data/user/0/academy.android.diveinback
packageList={academy.android.diveinback}
compat={420dpi}
thread=android.app.IApplicationThread$Stub$Proxy@7a708a2
pid=3558 starting=false
lastActivityTime=-12m28s333ms lastPssTime=-10m48s392ms nextPssTime=+19m11s582ms
adjSeq=9790 lruSeq=0 lastPss=41MB lastSwapPss=0.00 lastCachedPss=41MB lastCachedSwapPss=0.00
cached=true empty=true
oom: max=1001 curRaw=906 setRaw=906 cur=906 set=906
curSchedGroup=0 setSchedGroup=0 systemNoUi=false trimMemoryLevel=0
curProcState=17 repProcState=17 pssProcState=17 setProcState=17 lastStateTime=-11m28s398ms
hasShownUi=true pendingUiClean=false hasAboveClient=false treatLikeActivity=false
lastWakeTime=3029 timeUsed=+1m0s7ms
lastCpuTime=0 timeUsed=0
lastRequestedGc=-12m31s686ms lastLowMemory=-12m31s686ms reportLowMemory=false
Tips/Tricks JobScheduler
Maintain the progress
Backward compatibility.
Should I use JobScheduler only?
Should I have Service & jobscheduler
JobIntentService
Context.startService()
< >=
JobScheduler.enqueue()
JobIntentService
onStartJob(JobParams)
JobService
onHandleWork(Intent intent);
onStopJob(JobParams ) onStopCurrentWork()
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
public class MainActivity
Job myJob = firebaseJobDispatcher.newJobBuilder()
.setService(SmartService.class)
.setTag(SmartService.LOCATION_SMART_JOB)
.setRecurring(true)
.setLifetime(FOREVER)
.setTrigger(Trigger.executionWindow(0, 60 * 5))
.setReplaceCurrent(false)
.setConstraints(ON_ANY_NETWORK)
.build();
firebaseJobDispatcher.mustSchedule(myJob);
Avoid JobId collision
Jobs Not Rescheduled after Reboot
https://github.com/firebase/firebase-jobdispatcher-android/issues/101
Last thing...
How the phone with no battery left looks?
Yonatan V.Levin levin.yonatan
parahallGoogle Developer Expert

More Related Content

Similar to Background Life with Android O and beyond - Yonatan Levin, KolGene

Battery Efficient Location Services
Battery Efficient Location ServicesBattery Efficient Location Services
Battery Efficient Location Services
Arun Nagarajan
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Codemotion
 
How to Build Your Own Ride-Share App - codemotion amsterdam 2019
How to Build Your Own Ride-Share App - codemotion amsterdam 2019How to Build Your Own Ride-Share App - codemotion amsterdam 2019
How to Build Your Own Ride-Share App - codemotion amsterdam 2019
Richard Süselbeck
 
google play service 7.8 & new tech in M
google play service 7.8 & new tech in M google play service 7.8 & new tech in M
google play service 7.8 & new tech in M
Ted Liang
 
Creating an Uber Clone - Part XV.pdf
Creating an Uber Clone - Part XV.pdfCreating an Uber Clone - Part XV.pdf
Creating an Uber Clone - Part XV.pdf
ShaiAlmog1
 
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
Matthias Noback
 
Solid principles in practice the clean architecture - Droidcon Italy
Solid principles in practice the clean architecture - Droidcon ItalySolid principles in practice the clean architecture - Droidcon Italy
Solid principles in practice the clean architecture - Droidcon Italy
Fabio Collini
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
Astrails
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
Matteo Bonifazi
 
A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014
Matthias Noback
 
Average- An android project
Average- An android projectAverage- An android project
Average- An android projectIpsit Dash
 
Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Cluster
miciek
 
Creating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdfCreating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdf
ShaiAlmog1
 
Android wearpp
Android wearppAndroid wearpp
Android wearpp
Paul Trebilcox-Ruiz
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intent
admin220812
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
Pavel Lahoda
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon Berlin
 
Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.
Yonatan Levin
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
Christoffer Noring
 

Similar to Background Life with Android O and beyond - Yonatan Levin, KolGene (20)

Battery Efficient Location Services
Battery Efficient Location ServicesBattery Efficient Location Services
Battery Efficient Location Services
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
How to Build Your Own Ride-Share App - codemotion amsterdam 2019
How to Build Your Own Ride-Share App - codemotion amsterdam 2019How to Build Your Own Ride-Share App - codemotion amsterdam 2019
How to Build Your Own Ride-Share App - codemotion amsterdam 2019
 
google play service 7.8 & new tech in M
google play service 7.8 & new tech in M google play service 7.8 & new tech in M
google play service 7.8 & new tech in M
 
Creating an Uber Clone - Part XV.pdf
Creating an Uber Clone - Part XV.pdfCreating an Uber Clone - Part XV.pdf
Creating an Uber Clone - Part XV.pdf
 
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
A Series of Fortunate Events - Drupalcon Europe, Amsterdam 2014
 
Solid principles in practice the clean architecture - Droidcon Italy
Solid principles in practice the clean architecture - Droidcon ItalySolid principles in practice the clean architecture - Droidcon Italy
Solid principles in practice the clean architecture - Droidcon Italy
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014A Series of Fortunate Events - Symfony Camp Sweden 2014
A Series of Fortunate Events - Symfony Camp Sweden 2014
 
Introduction toandroid
Introduction toandroidIntroduction toandroid
Introduction toandroid
 
Average- An android project
Average- An android projectAverage- An android project
Average- An android project
 
Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Cluster
 
Creating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdfCreating an Uber Clone - Part XV - Transcript.pdf
Creating an Uber Clone - Part XV - Transcript.pdf
 
Android wearpp
Android wearppAndroid wearpp
Android wearpp
 
Android Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and IntentAndroid Event and IntentAndroid Event and Intent
Android Event and IntentAndroid Event and Intent
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.Knock, knock, who is there? Doze.
Knock, knock, who is there? Doze.
 
Rxjs swetugg
Rxjs swetuggRxjs swetugg
Rxjs swetugg
 

More from DroidConTLV

Mobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, NikeMobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, Nike
DroidConTLV
 
Doing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra TechnologiesDoing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra Technologies
DroidConTLV
 
No more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola SolutionsNo more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola Solutions
DroidConTLV
 
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.comMobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
DroidConTLV
 
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, ClimacellLiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
DroidConTLV
 
MVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, LightricksMVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, Lightricks
DroidConTLV
 
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
DroidConTLV
 
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice NinjaBuilding Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice Ninja
DroidConTLV
 
New Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy ZukanovNew Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy Zukanov
DroidConTLV
 
Designing a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, GettDesigning a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, Gett
DroidConTLV
 
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperThe Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
DroidConTLV
 
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDevKotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
DroidConTLV
 
Flutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, TikalFlutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, Tikal
DroidConTLV
 
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisReactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
DroidConTLV
 
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevelFun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
DroidConTLV
 
DroidconTLV 2019
DroidconTLV 2019DroidconTLV 2019
DroidconTLV 2019
DroidConTLV
 
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, MondayOk google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
DroidConTLV
 
Introduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, WixIntroduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, Wix
DroidConTLV
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
DroidConTLV
 
Educating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirEducating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz Tamir
DroidConTLV
 

More from DroidConTLV (20)

Mobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, NikeMobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, Nike
 
Doing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra TechnologiesDoing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra Technologies
 
No more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola SolutionsNo more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola Solutions
 
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.comMobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
 
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, ClimacellLiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
 
MVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, LightricksMVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, Lightricks
 
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
 
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice NinjaBuilding Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice Ninja
 
New Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy ZukanovNew Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy Zukanov
 
Designing a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, GettDesigning a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, Gett
 
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperThe Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
 
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDevKotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
 
Flutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, TikalFlutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, Tikal
 
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisReactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
 
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevelFun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
 
DroidconTLV 2019
DroidconTLV 2019DroidconTLV 2019
DroidconTLV 2019
 
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, MondayOk google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
 
Introduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, WixIntroduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, Wix
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
 
Educating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirEducating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz Tamir
 

Recently uploaded

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 

Recently uploaded (20)

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 

Background Life with Android O and beyond - Yonatan Levin, KolGene

  • 2. >100 Cities > 30M usersRuby, Go, Python, Microservices Ooooops...
  • 4. ~ 2900 members Largest Android Active Community
  • 5. What Do We Do? ● Android Fundamentals ● Android UI / UX ● Community Hackathon ● Android Performance ● Mentors Program ● Active community
  • 7. Saving galaxy with 1% of battery
  • 9. It’s endless way to screw things
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. public class GettLocationService extends Service implements Handler.Callback public void onCreate() { handlerThread = new HandlerThread("RebelServiceHandlerThread"); handlerThread.start(); Looper looper = handlerThread.getLooper(); handler = new Handler(looper, this); handler.sendEmptyMessage(WHAT_MAKE_NETWORK_REQUEST); }
  • 19.
  • 21. @Override public void onCreate() { super.onCreate(); handlerThread = new HandlerThread("MyHandlerThread"); handlerThread.start(); looper = handlerThread.getLooper(); locationHandler = new LocationHandler(looper, getApplicationContext()); mReceiver = new NaiveBroadcastReceiver(); mNaiveNetworkHandler = new NetworkHandler(looper); } public class NaiveService extends Service {
  • 22. @Override public void onCreate() { super.onCreate(); handlerThread = new HandlerThread("MyHandlerThread"); handlerThread.start(); looper = handlerThread.getLooper(); locationHandler = new LocationHandler(looper, getApplicationContext()); mReceiver = new NaiveBroadcastReceiver(); mNaiveNetworkHandler = new NetworkHandler(looper); } public class NaiveService extends Service {
  • 23. @Override public void onCreate() { super.onCreate(); handlerThread = new HandlerThread("MyHandlerThread"); handlerThread.start(); looper = handlerThread.getLooper(); locationHandler = new LocationHandler(looper, getApplicationContext()); mNaiveNetworkHandler = new NetworkHandler(looper); mReceiver = new NaiveBroadcastReceiver(); } public class NaiveService extends Service {
  • 24. @Override public void onCreate() { super.onCreate(); handlerThread = new HandlerThread("MyHandlerThread"); handlerThread.start(); looper = handlerThread.getLooper(); locationHandler = new LocationHandler(looper, getApplicationContext()); mNaiveNetworkHandler = new NetworkHandler(looper); mReceiver = new NaiveBroadcastReceiver(); } public class NaiveService extends Service {
  • 25. public int onStartCommand(Intent intent, int flags, int startId) { LocalBroadcastManager.getInstance(this) .registerReceiver(mReceiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST); locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST); return super.onStartCommand(intent, flags, startId); } public class NaiveService extends Service {
  • 26. public int onStartCommand(Intent intent, int flags, int startId) { LocalBroadcastManager.getInstance(this) .registerReceiver(mReceiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST); locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST); return super.onStartCommand(intent, flags, startId); } public class NaiveService extends Service {
  • 27. public int onStartCommand(Intent intent, int flags, int startId) { LocalBroadcastManager.getInstance(this) .registerReceiver(mReceiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST); locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST); return super.onStartCommand(intent, flags, startId); } public class NaiveService extends Service {
  • 28. public int onStartCommand(Intent intent, int flags, int startId) { LocalBroadcastManager.getInstance(this) .registerReceiver(mReceiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST); locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST); return super.onStartCommand(intent, flags, startId); } public class NaiveService extends Service {
  • 29. public int onStartCommand(Intent intent, int flags, int startId) { LocalBroadcastManager.getInstance(this) .registerReceiver(mReceiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationHandler.removeMessages(LocationHandler.WHAT_LOCATION_REQUEST); locationHandler.sendEmptyMessage(LocationHandler.WHAT_LOCATION_REQUEST); return super.onStartCommand(intent, flags, startId); } public class NaiveService extends Service {
  • 30. @Override public void onDestroy() { LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver); locationHandler.removeCallbacksAndMessages(null); mNaiveNetworkHandler.removeCallbacksAndMessages(null); locationHandler.stop(); locationHandler = null; mNaiveNetworkHandler = null; looper.quit(); handlerThread.quit(); locationHandler = null; } public class NaiveService extends Service {
  • 31. public class LocationHandler extends Handler { LocationHandler(Looper looper, Context context) { super(looper); locationTracker = new LocationTracker(context, getLooper()); } public void handleMessage(Message msg) { switch (msg.what) { case WHAT_LOCATION_REQUEST: sendEmptyMessageDelayed(WHAT_LOCATION_REQUEST, FIVE_MINUTES); locationTracker.start(); } }
  • 32. public class LocationHandler extends Handler { LocationHandler(Looper looper, Context context) { super(looper); locationTracker = new LocationTracker(context, getLooper()); } public void handleMessage(Message msg) { switch (msg.what) { case WHAT_LOCATION_REQUEST: sendEmptyMessageDelayed(WHAT_LOCATION_REQUEST, FIVE_MINUTES); locationTracker.start(); } }
  • 33. public class LocationHandler extends Handler { LocationHandler(Looper looper, Context context) { super(looper); locationTracker = new LocationTracker(context, getLooper()); } public void handleMessage(Message msg) { switch (msg.what) { case WHAT_LOCATION_REQUEST: sendEmptyMessageDelayed(WHAT_LOCATION_REQUEST, FIVE_MINUTES); locationTracker.start(); } }
  • 34. public class LocationHandler extends Handler { void stop() { locationTracker.stop(); }
  • 36. class LocationTracker { private void broadcastLocation(Location location) { if (mWeakReference.get() != null) { Intent intent = new Intent(NaiveService.NaiveBroadcastReceiver.ACTION_NEW_LOCATION_ARRIVED); intent.putExtra(NaiveService.NaiveBroadcastReceiver.LOCATION_KEY, location); LocalBroadcastManager.getInstance(mWeakReference.get()).sendBroadcast(intent); } }
  • 37. class LocationTracker { private void broadcastLocation(Location location) { if (mWeakReference.get() != null) { Intent intent = new Intent(NaiveService.NaiveBroadcastReceiver.ACTION_NEW_LOCATION_ARRIVED); intent.putExtra(NaiveService.NaiveBroadcastReceiver.LOCATION_KEY, location); LocalBroadcastManager.getInstance(mWeakReference.get()).sendBroadcast(intent); } }
  • 38. class LocationTracker { private void broadcastLocation(Location location) { if (mWeakReference.get() != null) { Intent intent = new Intent(NaiveService.NaiveBroadcastReceiver.ACTION_NEW_LOCATION_ARRIVED); intent.putExtra(NaiveService.NaiveBroadcastReceiver.LOCATION_KEY, location); LocalBroadcastManager.getInstance(mWeakReference.get()).sendBroadcast(intent); } }
  • 39. public class NaiveBroadcastReceiver extends LocationBaseBroadcast { public void onReceive(Context context, Intent intent) { Location location = intent.getExtras().getParcelable(LOCATION_KEY); Message message = mNaiveNetworkHandler.obtainMessage(NetworkHandler.WHAT_SEND_NAIVE_REPORT, location); mNaiveNetworkHandler.sendMessage(message); } }
  • 40. public class NaiveBroadcastReceiver extends LocationBaseBroadcast { public void onReceive(Context context, Intent intent) { Location location = intent.getExtras().getParcelable(LOCATION_KEY); Message message = mNaiveNetworkHandler.obtainMessage(NetworkHandler.WHAT_SEND_NAIVE_REPORT, location); mNaiveNetworkHandler.sendMessage(message); } }
  • 41. public class NaiveBroadcastReceiver extends LocationBaseBroadcast { public void onReceive(Context context, Intent intent) { Location location = intent.getExtras().getParcelable(LOCATION_KEY); Message message = mNaiveNetworkHandler.obtainMessage(NetworkHandler.WHAT_SEND_NAIVE_REPORT, location); mNaiveNetworkHandler.sendMessage(message); } }
  • 42. public class NetworkHandler extends Handler { @Override public void handleMessage(Message msg) { switch (msg.what) { case WHAT_SEND_NAIVE_REPORT: Location location = (Location) msg.obj; ServerReport serverReport = new ServerReport(location); FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("NaiveReport"); myRef.push().setValue(serverReport); Break; } }
  • 43. public class NetworkHandler extends Handler { @Override public void handleMessage(Message msg) { switch (msg.what) { case WHAT_SEND_NAIVE_REPORT: Location location = (Location) msg.obj; ServerReport serverReport = new ServerReport(location); FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("NaiveReport"); myRef.push().setValue(serverReport); Break; } }
  • 44. public class NetworkHandler extends Handler { @Override public void handleMessage(Message msg) { switch (msg.what) { case WHAT_SEND_NAIVE_REPORT: Location location = (Location) msg.obj; ServerReport serverReport = new ServerReport(location); FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("NaiveReport"); myRef.push().setValue(serverReport); Break; } }
  • 45. public class NetworkHandler extends Handler { @Override public void handleMessage(Message msg) { switch (msg.what) { case WHAT_SEND_NAIVE_REPORT: Location location = (Location) msg.obj; ServerReport serverReport = new ServerReport(location); FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("NaiveReport"); myRef.push().setValue(serverReport); Break; } }
  • 47.
  • 48.
  • 49.
  • 53. Few times in an hour
  • 57. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 58. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 59. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 60. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 61. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 62. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 63. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 64. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 65. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 66. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 67. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 68. public class SmartService extends JobService { public static final String LOCATION_SMART_JOB = "LOCATION_SMART_JOB";
  • 69. public class SmartService extends JobService { public boolean onStartJob(JobParameters jobParameters) { LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationTracker.start(); return true; } public boolean onStopJob(JobParameters jobParameters) { locationTracker.stop(); return true; }
  • 70. public class SmartService extends JobService { public boolean onStartJob(JobParameters jobParameters) { LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationTracker.start(); return true; } public boolean onStopJob(JobParameters jobParameters) { locationTracker.stop(); return true; }
  • 71. public class SmartService extends JobService { public boolean onStartJob(JobParameters jobParameters) { LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationTracker.start(); return true; } public boolean onStopJob(JobParameters jobParameters) { locationTracker.stop(); return true; }
  • 72. public class SmartService extends JobService { public boolean onStartJob(JobParameters jobParameters) { LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationTracker.start(); return true; } public boolean onStopJob(JobParameters jobParameters) { locationTracker.stop(); return true; }
  • 73. public class SmartService extends JobService { public boolean onStartJob(JobParameters jobParameters) { LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationTracker.start(); return true; } public boolean onStopJob(JobParameters jobParameters) { locationTracker.stop(); return true; }
  • 74. public class SmartService extends JobService { public boolean onStartJob(JobParameters jobParameters) { LocalBroadcastManager.getInstance(this).registerReceiver(receiver, new IntentFilter(LocationBaseBroadcast.ACTION_NEW_LOCATION_ARRIVED)); locationTracker.start(); return true; } public boolean onStopJob(JobParameters jobParameters) { locationTracker.stop(); return true; }
  • 76.
  • 77. Same
  • 78. Is it so good? :)
  • 79.
  • 80. public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startService(new Intent(this, MyService.class)); startService(new Intent(this, MyIntentService.class)); }
  • 81. public class MyService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); //... }
  • 82. public class MyService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); //... }
  • 83. public class MyService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); final PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); //... }
  • 84. public class MyService extends Service { Thread thread = new Thread(new Runnable() { @Override public void run() { wakeLock.acquire(); while(true){ try { Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); } } } });
  • 85. public class MyService extends Service { Thread thread = new Thread(new Runnable() { @Override public void run() { wakeLock.acquire(); while(true){ try { Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); } } } });
  • 86. public class MyService extends Service { Thread thread = new Thread(new Runnable() { @Override public void run() { wakeLock.acquire(); while(true){ try { Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); } } } });
  • 87. public class MyService extends Service { //... thread.start(); return super.onStartCommand(intent, flags, startId); }
  • 88. Will it blend? 1. After a some time service will die, wakelock will be released, thread will be parked 2. Service will die, wakelock will be never released, thread will run till process will be killed 3. Service will continue to run till it stopped 4. Service will die, system will release wakelock and after some time thread will be parked
  • 89. Will it blend? 1. After a some time service will die, wakelock will be released, thread will be parked 2. Service will die, wakelock will be never released, thread will run till process will be killed 3. Service will continue to run till it stopped 4. Service will die, system will release wakelock and after some time thread will be parked
  • 90. Will it blend? 1. After a some time service will die, wakelock will be released, thread will be parked 2. Service will die, wakelock will be never released, thread will run till process will be killed 3. Service will continue to run endless 4. Service will die, system will release wakelock and after some time thread will be parked
  • 91. Will it blend? 1. After a some time service will die, wakelock will be released, thread will be parked 2. Service will die, wakelock will be never released, thread will run till process will be killed 3. Service will continue to run endless 4. After a some time service will die, wakelock will be released, thread will be terminated
  • 92. Will it blend? 1. After a some time service will die, wakelock will be released, thread will be parked 2. Service will die, wakelock will be never released, thread will run till process will be killed 3. Service will continue to run endless 4. After a some time service will die, wakelock will be released, thread will be terminated
  • 93. ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes) All known processes: *APP* UID 10084 ProcessRecord{f5cc46d 3558:academy.android.diveinback/u0a84} user #0 uid=10084 gids={50084, 20084, 9997} requiredAbi=x86 instructionSet=null class=academy.android.diveinback.MyApp dir=/data/app/academy.android.diveinback-ks7V4YegT65dnRcooFAcwA==/base.apk publicDir=/data/app/academy.android.diveinback-ks7V4YegT65dnRcooFAcwA==/base.apk data=/data/user/0/academy.android.diveinback packageList={academy.android.diveinback} compat={420dpi} thread=android.app.IApplicationThread$Stub$Proxy@7a708a2 pid=3558 starting=false lastActivityTime=-12m28s333ms lastPssTime=-10m48s392ms nextPssTime=+19m11s582ms adjSeq=9790 lruSeq=0 lastPss=41MB lastSwapPss=0.00 lastCachedPss=41MB lastCachedSwapPss=0.00 cached=true empty=true oom: max=1001 curRaw=906 setRaw=906 cur=906 set=906 curSchedGroup=0 setSchedGroup=0 systemNoUi=false trimMemoryLevel=0 curProcState=17 repProcState=17 pssProcState=17 setProcState=17 lastStateTime=-11m28s398ms hasShownUi=true pendingUiClean=false hasAboveClient=false treatLikeActivity=false lastWakeTime=3029 timeUsed=+1m0s7ms lastCpuTime=0 timeUsed=0 lastRequestedGc=-12m31s686ms lastLowMemory=-12m31s686ms reportLowMemory=false
  • 96. Backward compatibility. Should I use JobScheduler only? Should I have Service & jobscheduler
  • 99. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 100. public class MainActivity Job myJob = firebaseJobDispatcher.newJobBuilder() .setService(SmartService.class) .setTag(SmartService.LOCATION_SMART_JOB) .setRecurring(true) .setLifetime(FOREVER) .setTrigger(Trigger.executionWindow(0, 60 * 5)) .setReplaceCurrent(false) .setConstraints(ON_ANY_NETWORK) .build(); firebaseJobDispatcher.mustSchedule(myJob);
  • 102. Jobs Not Rescheduled after Reboot https://github.com/firebase/firebase-jobdispatcher-android/issues/101
  • 104. How the phone with no battery left looks?
  • 105.