import android.os.Looper;
import android.os.Message;
import android.os.Process;
+import android.util.Log;
import android.util.Pair;
public class OperationsService extends Service {
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- //Log.wtf(TAG, "onStartCommand init" );
+ Log.wtf(TAG, "onStartCommand init" );
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
mServiceHandler.sendMessage(msg);
- //Log.wtf(TAG, "onStartCommand end" );
+ Log.wtf(TAG, "onStartCommand end" );
return START_NOT_STICKY;
}
-
+ @Override
+ public void onDestroy() {
+ Log.wtf(TAG, "onDestroy init" );
+ super.onDestroy();
+ Log.wtf(TAG, "Clear mOperationResults" );
+ mOperationResults.clear();
+ Log.wtf(TAG, "onDestroy end" );
+ }
+
+
/**
* Provides a binder object that clients can use to perform actions on the queue of operations,
* except the addition of new operations.
*/
@Override
public IBinder onBind(Intent intent) {
- //Log.wtf(TAG, "onBind" );
+ Log.wtf(TAG, "onBind" );
return mBinder;
}
}
}
- public RemoteOperationResult getOperationResultIfFinished(int mDetectAuthOpId) {
- //Log_OC.wtf(TAG, "Searching result for operation with id " + mDetectAuthOpId);
- return mOperationResults.remove(mDetectAuthOpId);
+ public RemoteOperationResult getOperationResultIfFinished(int operationId) {
+ Log_OC.wtf(TAG, "Searching result for operation with id " + operationId);
+ return mOperationResults.remove(operationId);
}
}
*/
private void nextOperation() {
- //Log.wtf(TAG, "nextOperation init" );
+ Log.wtf(TAG, "nextOperation init" );
Pair<Target, RemoteOperation> next = null;
synchronized(mPendingOperations) {
} finally {
synchronized(mPendingOperations) {
mPendingOperations.poll();
- mOperationResults.put(mCurrentOperation.hashCode(), result);
}
}
//sendBroadcastOperationFinished(mLastTarget, mCurrentOperation, result);
- callbackOperationListeners(mLastTarget, mCurrentOperation, result);
+ dispatchOperationListeners(mLastTarget, mCurrentOperation, result);
}
}
* @param operation Finished operation.
* @param result Result of the operation.
*/
- private void callbackOperationListeners(
+ private void dispatchOperationListeners(
Target target, final RemoteOperation operation, final RemoteOperationResult result) {
int count = 0;
Iterator<OnRemoteOperationListener> listeners = mBinder.mBoundListeners.keySet().iterator();
count += 1;
}
}
+ if (count == 0) {
+ mOperationResults.put(operation.hashCode(), result);
+ }
Log_OC.d(TAG, "Called " + count + " listeners");
}