简体   繁体   中英

Block until a task finished in onAnimationEnd

I have a login activity which has an animation displaying the logo picture, and the login process is running in the background during the animation running. I want to wait until both the animation and the login process finished to execute the next part of the program.
My first attempt is put the login process in a thread, and in onAnimationEnd use thread.join() to block until the thread finished.
It seems to be a good solution, however since I use thread.join() , the main UI thread was blocked, hence ANR may occure. I've tried to use AsyncTask , however it cannot handle onAnimationEnd event. Is there any other way to solute the problem?

The code is like this:

protected void onCreate(Bundle savedInstanceState) {
    ........
    title.startAnimation(set);
    loginProcess.start();
    ........
}

public void onAnimationEnd(Animation animation) {
    try {
        loginProcess.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    ........
}

Just use an AsyncTask and do something like:

@Override
protected void onPreExecute() {
        title.startAnimation(set);
}

@Override
protected void onPostExecute(String result) {
       title.clearAnimation();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM