package net.tevp.postcode;

import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.widget.TextView;
import android.location.Location;

public class Postcode extends Activity implements PostcodeListener {	
	TextView tv;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) findViewById(R.id.Postcode);
        tv.setText("Finding location..");
		new PostcodeBackend().getPostcode(this,this);
    }

	public static void main(String[] args) throws Exception {
		String[] coords = args[0].split(",");
		assert coords.length == 2;
		System.out.println(PostcodeBackend.get(Double.parseDouble(coords[0]),Double.parseDouble(coords[1])));
	}

	private void setText(final String text)
	{
		final TextView myTV = tv;		
		runOnUiThread(new Runnable()
		{
			public void run()
			{
				myTV.setText(text);
			}
		});
	}

	public void postcodeChange(String postcode)
	{
		setText(postcode);
	}

	public void updatedLocation(Location l)
	{
		setText("Found location, looking for postcode...");
	}
}

@@ -259,16 +259,37 @@
 iew tv;%0A
+%09PostcodeBackend pb;%0A
 %09%0A%09/** C
@@ -581,16 +581,100 @@
 ..%22);%0A%09%09
+pb = (PostcodeBackend) getLastNonConfigurationInstance();%0A%09%09if (pb == null)%0A%09%09%09pb = 
 new Post
@@ -686,16 +686,22 @@
 ackend()
+;%0A%09%09pb
 .getPost
@@ -1307,11 +1307,92 @@
 ..%22);%0A%09%7D
+%0A%0A%09@Override%0A%09public Object onRetainNonConfigurationInstance()%0A%09%7B%0A%09%09return pb;%0A%09%7D
 %0A%7D%0A

Maintain state after rotation