I have a parent activity, and a child activity that extends the parent activity. When the parent starts the child activity,
Which onCreate gets executed first? The child's or parent's?
There is a particular variable I am setting in the Child activity's onCreate method, and right now, it looks like it takes a while to get to the Child activity's onCreate, and so the methods in the Parent are reporting an empty variable. Whereas when I make the Parent sleep for a while, it reports the correct variable.
Thanks Chris
Parent Activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
goButton = (ImageButton) this.findViewById(R.id.goButton);
goButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Intent childIntent = new Intent("com.example.Child");
String newValue = "Child Value";
Bundle bun = new Bundle();
bun.putString("value", newValue); // add two parameters: a string and a boolean
childIntent.putExtras(bun);
startActivity(childIntent);
}
});
this.doTheWork("Parent Value");
}
private void doTheWork(String value) {
new MyNewThread(value).start();
}
public String getTheValue(String value) {
return "My Value is: " + value;
}
private class MyNewThread extends Thread {
String value;
public LoadThread(String v) {
this.value = v;
}
@Override
public void run() {
String str = getTheValue(this.value);
}
}
Child Activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bun = getIntent().getExtras();
childValue = bun.getString("value");
}
public String getTheValue(String value) {
return "My Value is: " + value;
}
So, basically, even after the Parent starts the Child, it still returns "Parent Value", but when I have the thread sleep, it return "Child Value".