Do not hardcode service name in HandlerService

This commit is contained in:
YuviPanda 2013-03-21 23:47:14 +05:30
parent ac5e94bf25
commit 67e3b645cb
2 changed files with 10 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import android.os.*;
public abstract class HandlerService<T> extends Service { public abstract class HandlerService<T> extends Service {
private volatile Looper threadLooper; private volatile Looper threadLooper;
private volatile ServiceHandler threadHandler; private volatile ServiceHandler threadHandler;
private String serviceName;
private final class ServiceHandler extends Handler { private final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) { public ServiceHandler(Looper looper) {
@ -39,10 +40,14 @@ public abstract class HandlerService<T> extends Service {
return localBinder; return localBinder;
} }
protected HandlerService(String serviceName) {
this.serviceName = serviceName;
}
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
HandlerThread thread = new HandlerThread("UploadService"); HandlerThread thread = new HandlerThread(serviceName);
thread.start(); thread.start();
threadLooper = thread.getLooper(); threadLooper = thread.getLooper();

View file

@ -39,6 +39,10 @@ public class UploadService extends HandlerService<Contribution> {
public static final int NOTIFICATION_UPLOAD_COMPLETE = 2; public static final int NOTIFICATION_UPLOAD_COMPLETE = 2;
public static final int NOTIFICATION_UPLOAD_FAILED = 3; public static final int NOTIFICATION_UPLOAD_FAILED = 3;
protected UploadService(String serviceName) {
super("UploadService");
}
private class NotificationUpdateProgressListener implements ProgressListener { private class NotificationUpdateProgressListener implements ProgressListener {
String notificationTag; String notificationTag;