]> average.org Git - WhereAmI.git/commitdiff
Use async task
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Wed, 25 Jan 2012 16:51:07 +0000 (20:51 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Wed, 25 Jan 2012 16:51:07 +0000 (20:51 +0400)
res/layout/main.xml
src/org/average/whereami/WhereAmI.java

index 659a7dbbd15a349e2031622d1d86c313eb58d110..cb95f7ad5eb8d1af95b726ba42dcd7c0a774ed78 100644 (file)
@@ -6,8 +6,10 @@
     android:background="#ffffffff"
 >
   <TextView
+    android:id="@+id/tv"
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
+    android:gravity="center"
     android:layout_weight="1"
     android:textColor="#ff000000"
     android:text="Hello, WhereAmI?!"
index 6fdbf34935b0bd42418938438036f319ba0d184d..2f69212af35f023f542cd6d4a5a310d29e242426 100644 (file)
@@ -2,8 +2,12 @@ package org.average.whereami;
 
 import android.app.Activity;
 import android.os.Bundle;
+import android.os.AsyncTask;
+import android.util.Log;
+import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
+import android.widget.TextView;
 
 public class WhereAmI extends Activity
 {
@@ -16,5 +20,29 @@ public class WhereAmI extends Activity
         getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
         getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
         setContentView(R.layout.main);
+        Log.v("WhereAmI", "created UI, about to start update task");
+        new TimedUpdateTask().execute(5);
+        Log.v("WhereAmI", "created UI, update task created");
+    }
+
+    private class TimedUpdateTask extends AsyncTask<Integer, Void, String> {
+       @Override
+        protected String doInBackground(Integer... howlong) {
+            Log.v("TimedUpdateTask", "starting");
+            try {
+                Thread.sleep(1000 * howlong[0]);
+            } catch (InterruptedException e) {
+                Log.e("TimedUpdateTask", "sleep interrupted");
+            }
+            Log.v("TimedUpdateTask", "about to return");
+            return (Integer.toString(howlong[0]) + " seconds passed");
+        }
+    
+       @Override
+        protected void onPostExecute(String str) {
+            TextView tv = (TextView)findViewById(R.id.tv);
+            Log.v("TimedUpdateTask", "callback executing");
+            tv.append("\n" + str);
+        }
     }
 }