From 6a030381607aaf7b44529c4d5a6552749305c3d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 28 Feb 2012 11:57:48 +0100 Subject: Run SameService in a separate process. --- .../java/com/orbekk/same/VariableTestActivity.java | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'same-android/src/main/java/com/orbekk/same/VariableTestActivity.java') diff --git a/same-android/src/main/java/com/orbekk/same/VariableTestActivity.java b/same-android/src/main/java/com/orbekk/same/VariableTestActivity.java index 1fffbad..3ae1a87 100644 --- a/same-android/src/main/java/com/orbekk/same/VariableTestActivity.java +++ b/same-android/src/main/java/com/orbekk/same/VariableTestActivity.java @@ -4,6 +4,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import android.app.Activity; +import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.widget.EditText; @@ -27,6 +28,22 @@ public class VariableTestActivity extends Activity { } }; + private class UpdateVariableTask + extends AsyncTask { + @Override protected DelayedOperation.Status doInBackground(String... values) { + String value = values[0]; + return variable.set(value).getStatus(); + } + + @Override protected void onPostExecute(DelayedOperation.Status status) { + if (!status.isOk()) { + Toast.makeText(VariableTestActivity.this, + "Update failed: " + status, Toast.LENGTH_SHORT) + .show(); + } + } + } + private void displayVariable() { TextView tv = (TextView)findViewById(R.id.variable_text); if (variable.get() != null) { @@ -37,14 +54,7 @@ public class VariableTestActivity extends Activity { public void setVariable(View unused) { EditText et = (EditText)findViewById(R.id.set_variable_text); String newValue = et.getText().toString(); - logger.info("Setting variable."); - DelayedOperation op = variable.set(newValue); - logger.info("Waiting for delayed operation."); - if (!op.getStatus().isOk()) { - Toast.makeText(this, "Failed to update: " + op.getStatus(), - Toast.LENGTH_SHORT) - .show(); - } + new UpdateVariableTask().execute(newValue); } @Override public void onCreate(Bundle savedInstanceState) { -- cgit v1.2.3