Reputation: 2076
I need to start Activity in onCreate of another Activity and wait until activity2 finish. How to do that?
public class Activity1 extends Activity{
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
//do some code
startActivity(Activity2)
//wait until activity2 finish
//another code which can be done after activity2 finish
}
...
}
Or I need to do another code
in OnActivityResult async way??
Upvotes: 1
Views: 6796
Reputation: 573
You should try this way...
public class FirstActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(SecondActivity.this, getApplicationContext());
int requestCode = 0;
startActivityForResult(i,requestCode);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// do your stuff here after SecondActivity finished.
}
}
Hope this helps you.
Upvotes: 3
Reputation: 435
You can start activity2 like startActivityForResult(intent, requestCode).
And do what ever you want to do in onActivityResult(int arg0, int arg1, Intent arg2) on finsh activity2.
Upvotes: 1
Reputation: 116
You can use startActivtyForResult method to start the activty2 then when onActivityResult of activty1 called call setContentView for the first one
Upvotes: 2
Reputation: 2575
You can use startActivityForResult and then catch the result in OnActivityResult
Upvotes: 1