Service implementation
This commit is contained in:
@@ -12,11 +12,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
* Date: 3/5/12
|
||||
* Time: 10:23 PM
|
||||
*/
|
||||
public class CalculationService extends Service {
|
||||
public class CalculationServiceImpl extends Service implements ICalculationService {
|
||||
|
||||
@NotNull
|
||||
private ServiceHandler handler;
|
||||
|
||||
public CalculationServiceImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Toast.makeText(this, ".CalculationService.onStartCommand", Toast.LENGTH_SHORT).show();
|
||||
@@ -56,7 +59,7 @@ public class CalculationService extends Service {
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
return new LocalBinder<ICalculationService>(this);
|
||||
}
|
||||
|
||||
private final class ServiceHandler extends Handler {
|
||||
@@ -67,7 +70,7 @@ public class CalculationService extends Service {
|
||||
|
||||
@Override
|
||||
public void handleMessage(@NotNull Message msg) {
|
||||
Toast.makeText(CalculationService.this, "Doing job!", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(CalculationServiceImpl.this, "Doing job!", Toast.LENGTH_SHORT).show();
|
||||
stopSelf(msg.arg1);
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 3/5/12
|
||||
* Time: 10:23 PM
|
||||
*/
|
||||
public interface ICalculationService {
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.os.Binder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* A generic implementation of Binder to be used for local services
|
||||
*
|
||||
* @param <S> The type of the service being bound
|
||||
* @author Geoff Bruckner 12th December 2009
|
||||
*/
|
||||
|
||||
public class LocalBinder<S> extends Binder {
|
||||
|
||||
@NotNull
|
||||
private static String TAG = "LocalBinder";
|
||||
|
||||
@NotNull
|
||||
private WeakReference<S> serviceReference;
|
||||
|
||||
|
||||
public LocalBinder(@NotNull S service) {
|
||||
serviceReference = new WeakReference<S>(service);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public S getService() {
|
||||
return serviceReference.get();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user