Reputation: 326
I have an activity which contains a back button. when it is pressed, it starts another activity which contains a back button in same position. But the problem is it takes few seconds to start activity because it does some heavy task in background. Now the problem is, if the user press back button again before starting the new activity, the second press goes to new activity and the it navigates from new activity to another new activity. I think the problem is clear to you. Any idea how to solve this problem??? Thanx.
Upvotes: 0
Views: 640
Reputation: 4433
You can disable the button when pressed once like
Button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Button1.setEnabled(false);
}
});
Upvotes: 1
Reputation: 2425
It sounds like you are blocking the main thread to perform your "heavy task", I would advise that you start the new Activity, then onCreate fire an AsyncTask to perform your "heavy task".
This way the view will load fast and you can show a dialog to the user to say that it's loading.
Link to AsyncTask tutorial: http://droidapp.co.uk/2011/05/12/android-dev-pre-loading-with-asynctask/
Upvotes: 0