I would like to show loadingActivity while “activity1” is executing some code (working), after that, show again activity1. However, if I do not want to start activity1 again, only switch its layouts when doSomeStuff ends. Thank you.
activity1
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent myIntent = new Intent(getApplicationContext(), loadingActivity.class);
startActivityForResult(myIntent, 0);
//Do some stuff while loadingActivity is showed
doSomeStuff()
//here I want to show again this activity and hide loading one
loadingActivity
public class loadingActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setContentView(R.layout.loading);
}
For this you should use a
ProgressDialog, this will allow you to easily show a loading indicator and once the work is done you can easily remove it. The code below should work of you.Show Dialog:
Dismiss dialog:
You can set the dialog as a class level variable if you want to show and dismiss it in different methods.
Also from looking at your code you might be blocking the activity from ever loading if your long running work is not happening on a background thread. You cannot do long running work inside of onCreate without offloading the work to a background thread. For easy threading in Android you should use the AsyncTask class.