Reputation: 5189
My MAIN activity is spawning a child activity that contains a ListView
. While this ListView
is being populated (through an AsyncTask
), an indeterminate progress bar is shown.
However, assuming that I am an impatient user and I press the BACK button, the progress bar is cancelled but I am left with a blank screen. I have to press BACK one more time to go back to the MAIN activity.
I would like the app to go back directly to the MAIN activity by pressing BACK only once. Can somebody point me in the right direction? I am thinking I should call finish()
somewhere but I don't know where to put it. Thanks in advance!
Upvotes: 0
Views: 615
Reputation: 629
you can try like this,place this code in your activities oncreate block.
findViewById(R.id.back).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
Upvotes: 0
Reputation: 3689
you should override "onBackPressed()" it will call when the activity has detected the user's press of the back key.
@override
public void onBackPressed(){
this.startActivity(this,MainActivity.class);
}
this code will call the MainActivity when emulator/ipphone back button pressed...
Upvotes: 0
Reputation: 8622
Use setOnCancelListener()
on Dialog (which ProgressDialog extends).
Upvotes: 1