Created
June 6, 2017 08:11
-
-
Save vtthach/a877baaa538666ad42bb34c4c25f90b8 to your computer and use it in GitHub Desktop.
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
package com.amb.counter2counter.service.ocr; | |
import android.app.Service; | |
import android.content.Intent; | |
import android.os.Binder; | |
import android.os.IBinder; | |
import timber.log.Timber; | |
/** | |
* Created by Thach.Vo on 4/25/2016. | |
*/ | |
public abstract class BaseStickyService<T> extends Service { | |
// Binder given to clients | |
private final IBinder mBinder = new LocalBinder(); | |
@Override | |
public int onStartCommand(Intent intent, int flags, int startId) { | |
Timber.i("Received start id " + startId + ": " + intent); | |
if (intent != null) { | |
onStartCheckIntent(intent); | |
} | |
return START_STICKY; // Run until explicitly stopped. | |
} | |
protected void onStartCheckIntent(Intent intent){ | |
// Stub method | |
} | |
@Override | |
public IBinder onBind(Intent intent) { | |
return mBinder; | |
} | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
Timber.i("OCR service - onDestroy"); | |
} | |
public abstract T getService(); | |
/** | |
* Class used for the client Binder. Because we know this service always | |
* runs in the same process as its clients, we don't need to deal with IPC. | |
*/ | |
public class LocalBinder extends Binder { | |
public T getService() { | |
// Return this instance of LocalService so clients can call public methods | |
return BaseStickyService.this.getService(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment