I have parent activity and child activity that extends parent activity. When a parent starts a child operation,
Which onCreate function is executed first? Child or parent?
There is a specific variable that I set in the Child activity onCreate method, and right now, it seems like it takes some time to go to the Child onCreate activity, and so the methods in the parent report an empty variable. Whereas when I make my parent sleep for a while, he reports the correct variable.
Thank you, 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);
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);
}
}
Activities of the child:
@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;
}
, , , Child, "Parent Value", , "Child Value".