I have two activities running: mainActivity and childActivity. Whenever the user clicks in the button in mainActivity, the childActivity is launched. What I want to do is this:
When the active activity is the childActivity and the user clicks the home button then relaunch the application, I want to see the childActivity instead of mainActivity that is launched.
I had some suggestions actually work arounds. I tried to manipulate onStart, onRestart, onResume, onStop, onDestroy events. But, they didn't fully solve the problem. There should be a smart way out there. Thank you.
Edit:
Thank you for the answer, Soonil. The case you said is happening when the activity is called from recent activities window. (the window opened when you long press the home button) However; This is not happening when you open it from home screen. (like opening from start) I don't think my code has a specific problem to generate this error. Because, I created a test project and tried standalone before sending the question and faced the same problem. Anyhow, here is the test code:
public class MainActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setTitle("MainActivity");
((Button) findViewById(R.id.btnChildActivity)).setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(this, ChildActivity.class));
}
}
public class ChildActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
this.setTitle("ChildActivity");
}
}