Use async task
[WhereAmI.git] / src / org / average / whereami / WhereAmI.java
index c74ab2d09e0f758a0e73ef9190beee84d4c01035..2f69212af35f023f542cd6d4a5a310d29e242426 100644 (file)
@@ -2,6 +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
 {
@@ -10,6 +16,33 @@ public class WhereAmI extends Activity
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
+        requestWindowFeature(Window.FEATURE_NO_TITLE);
+        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);
+        }
     }
 }