How to ensure 100% completion of time-consuming Android operations
習慣沉默
習慣沉默 2017-05-24 11:38:12
0
3
616

Novice Android developers encounter some doubts during the development process. I hope the experts can help guide me.
For example, my App needs to create a sqlite database when it is first installed.
My solution is to execute this creation method when the launcher starts the page.
But I think creating a sqlite database is a time-consuming operation. I need to put it in a sub-thread for execution
Then the question arises:
If the creation of the database in the sub-thread fails, how can I ensure that the subsequent methods can be executed smoothly?
When I create the database, the launcher may have jumped to mainActivity, or has been transferred to other pages, or is even ready to write data into the database, but at this time I can determine whether the database Exists. If it does not exist, I can re-create it, but it is impossible for me to re-create the database in all places where database operations are required.
So, how can I ensure that the operation results in the sub-thread are 100% completed?
And there are several other operations in the launcher, all of which need to be completed in child threads.
Solution.

習慣沉默
習慣沉默

reply all(3)
Peter_Zhu

1. Encapsulate it
2. For example, encapsulate a DBUtils layer.

bool checkDB(){
    return ..;
}
Beans DBUtils.query(callback){
    if(checkDb){
     callback(data);
    }
}
phpcn_u1582

It is recommended to use strong blocking logic and pop up the non-cancelable loading box to ensure the execution result.

Peter_Zhu

It is recommended to refer to the fact that when mobile QQ is started for the first time, there is a progress bar such as data initialization.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template