I now have it figured out. The issue I had with StartingSubactivities was just me being a "novice"...
However there are other discrepancies like the startSubActivity one I mentioned, that I couldn't get to work.
For instance (pg 56) you refer to "setResult(1, keyword)".
The setResult() method for Activity does not have any constructors accepting (int, string) arguments. Also on pg56, you refer to "onActivityResult(int,int,string,bundle)" but this method only has constructors accepting (int,int,Intent) arguments. Your code for "URI.parse..." on pg57 also didn't work as written.
Perhaps these are issues with the M5 to 0.9 conversion? (but I know even less about M5 than 0.9...).
Anyway, I think the following code addresses the issues described and works in SDK0.9:
Using java Syntax Highlighting
package org.anddev.andbook.startingsubactivities;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.util.Log;
public class MainActivity extends Activity {
public static final String MY_DEFAULTSTRING_ID = "defStrID";
private static final int MYSECONDACTIVITY_REQUESTCODE = 0x1337;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Find the Button from our XML-layout. */
Button b = (Button)this.findViewById(R.id.btn_open_search);
b.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// Place code to handle Button-Click here.
// Create an Intent to start MySecondActivity. */
Intent i = new Intent(
MainActivity.this, MySecondActivity.class);
//* Create a bundle which will be attached to the Intent, to carry
//* information to our MySecondActivity. */
Bundle b = new Bundle();
b.putString(MY_DEFAULTSTRING_ID, "www.google.com");
//* Attach Bundle to our Intent. */
i.putExtras(b);
//Send intent to the OS to make
// it aware that we want to start MySecondActivity as a SubActivity. */
startActivityForResult(i,MYSECONDACTIVITY_REQUESTCODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//* Check which SubActivity returned. * (Here we have only one.) */
switch(requestCode){
case MYSECONDACTIVITY_REQUESTCODE:
//* Create a new Intent to * show the Google-Search Page *
//with the keyword returned. */
Intent webIntent = new Intent( android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.google.com/search?q=" +
data.getExtras().
getString(MainActivity.MY_DEFAULTSTRING_ID)));
startActivity(webIntent);
break;
}
}
}
Parsed in 0.039 seconds, using
GeSHi 1.0.8.4
Using java Syntax Highlighting
package org.anddev.andbook.startingsubactivities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.util.Log;
public class MySecondActivity extends Activity {
//protected static final String KEYWORD_ID = "keyword1";
public Intent intent;
public EditText et_keyword;
//public String keyword;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
//* Get the EditText from the XML-file. */
et_keyword = (EditText) findViewById(R.id.et_keyword);
et_keyword.setText(getIntent().getExtras().getString(MainActivity.MY_DEFAULTSTRING_ID));
//* Get the return-Button from the XML-file. */
Button b2 = (Button)findViewById(R.id.btn_return);
//* Make that Button handle clicks to itself. */
b2.setOnClickListener(new MyOnClickListener());
}
class MyOnClickListener implements OnClickListener {
public void onClick(View arg0) {
//* Place code to handle Button-Click here. */
//* Retrieve the Text from the EditText. */
String keyword = et_keyword.getText().toString();
getIntent().putExtra(MainActivity.MY_DEFAULTSTRING_ID, keyword);
MySecondActivity.this.setResult(RESULT_OK, getIntent());
//* Our Activity is done and shall be closed. */
MySecondActivity.this.finish();
}
}
}
Parsed in 0.036 seconds, using
GeSHi 1.0.8.4