OK I put in the startActivityForResult and added an onActivityResult listener to receive the information. But the whole thing crashes on the return. It never makes it back to the calling program, where I am trying to pull out the values. I thought I would add a setResult in the called program, but that didn't change anything. I thought with all the nulls the log was reporting, I could clear it up by using setResult (int code, String data, Bundle extras), but I kept getting compile errors because that is not a method of activity.
I know this stuff is really simple, and you all have better things to do than debug my code, but I'd like to ask for a little more of your time. What did I miss this time? and how do I get this data back to the calling program?
Here is the new calling activity Foo:
Using java Syntax Highlighting
package android.test.Foo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Foo extends Activity {
public static boolean DEBUGING=true;
public static int CITY=1;
public String city="blank";
Intent i=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (DEBUGING){android.util.Log.v("MAINCREATE", "City = " + city);};
i=new Intent(Foo.this, Dialogs.class);
i.putExtra("CITY", city);
startActivityForResult(i,CITY);
}
@Override
public void onResume() {
super.onResume();
city=i.getStringExtra("CITY");
if (DEBUGING){android.util.Log.v("MAINRES", "city = " + city);};
}
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
city=data.getStringExtra("CITY");
if (DEBUGING){android.util.Log.v("ACTRESULT", "City = " + city);};
}
}
Parsed in 0.039 seconds, using
GeSHi 1.0.8.4
Here is the called activity Bar:
Using java Syntax Highlighting
package android.test.Foo;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Bar extends Activity {
static boolean DEBUGING=true;
Bundle b=null;
String city=null;
Button ack=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
b=this.getIntent().getExtras();
city=b.getString("CITY");
if (DEBUGING){android.util.Log.v("SUBCREATE", "City = " + city);};
setContentView(R.layout.regions);
ack=(Button)findViewById(R.id.ackbutton);
ack.setOnClickListener(onAck);
}
@Override
public void onResume() {
super.onResume();
}
private View.OnClickListener onAck=new View.OnClickListener() {
public void onClick(View v) {
city="Foo Bar";
b.putString("CITY", city);
if (DEBUGING){android.util.Log.v("SUBONCLICK", "City = " + city);};
setResult(RESULT_OK);
finish();
}
};
}
Parsed in 0.040 seconds, using
GeSHi 1.0.8.4
Here is the log:02-20 06:34:32.235: VERBOSE/MAINCREATE(320): City = blank
02-20 06:34:32.295: VERBOSE/MAINRES(320): city = blank
02-20 06:34:32.385: VERBOSE/SUBCREATE(320): City = blank
02-20 06:34:45.056: VERBOSE/SUBONCLICK(320): City = Foo Bar
After I hit ack button to shut down Bar:02-20 06:34:53.425: ERROR/AndroidRuntime(320): Uncaught handler: thread main exiting due to uncaught exception
02-20 06:34:53.455: ERROR/AndroidRuntime(320): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {android.test.Foo/android.test.Foo.Foo: java.lang.NullPointerException
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.app.ActivityThread.deliverResults(ActivityThread.java:3329)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3371)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.app.ActivityThread.access$2700(ActivityThread.java:119)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1893)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.os.Looper.loop(Looper.java:123)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at java.lang.reflect.Method.invoke(Method.java:521)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at dalvik.system.NativeStart.main(Native Method)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): Caused by: java.lang.NullPointerException
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.test.Foo.Foo.onActivityResult(Foo.java:36)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.app.Activity.dispatchActivityResult(Activity.java:3828)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): at android.app.ActivityThread.deliverResults(ActivityThread.java:3325)
02-20 06:34:53.455: ERROR/AndroidRuntime(320): ... 11 more