简体   繁体   中英

how to know an activity lifecycle method has finished running

I am using Robotium Solo for activity testing

i need to know that onCreate has finished running before i proceed with my test

i can tell it to sleep for 5 seconds, but that wont help, because i need the first row of onStart to be caught, and onCreate finishes at different times each time

how do i tell solo to wait until onCreate has finished?

this is what my code looks like :

solo.sleep(5000);

    solo.clickOnButton("animate");
    solo.sleep(5000);

    solo.clickOnButton("close");
    solo.sleep(5000);

    solo.clickOnButton("animate");
    solo.sleep(5000);

    solo.clickOnButton("close");
    solo.sleep(5000);

    solo.clickOnButton("animate");
    solo.sleep(5000);

    solo.clickOnButton("close");
    solo.sleep(5000);

you could add another method to search your controls to your code. For example:

static boolean clickOnButton(String name, Solo solo){
    Button view = null;
    try{
            ArrayList<Button> temp = solo.getCurrentViews(Button.class);
            for (int i = 0; i < temp.size(); i++) {
                if (temp.get(i).getText().toString().equals(name)){
                    view = temp.get(i);
                    break;
                }
            }
            view.click();
            return true;
    } catch (Error err) {
            return false;
    } 
}

If you are sure that the button will exist, you could loop such search, add some flag, make do-while cycle and change the flag by condition

    if (view == null)

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