简体   繁体   English

Android Espresso导航回活动

[英]Android Espresso navigating back to an activity

I am testing if form data is retained or not when back key is pressed and user navigates back to the form Activity. 我正在测试在按返回键并导航回表单活动时是否保留表单数据。

Expected Flow: Press Register Button -> Goto Form page and fill it up -> Press back button -> Press Register Button -> Verify form data is retained 预期的流程:按注册按钮->转到表单页面并填写->按后退按钮->按注册按钮->确认保留表单数据

Actual Flow: Espresso launches Form Page -> Press back button -> App Quits 实际流程: Espresso启动表单页面->按返回按钮->应用退出

Espresso start from Form Page because that's how the ActivityRule is defined. Espresso从Form Page开始,因为这是ActivityRule的定义方式。

public ActivityTestRule<RegisterActivity> mActivity = new ActivityTestRule<>(RegisterActivity.class);

I tried to startActivity() for the Registration Button page, but when I press back, it navigates back to the empty Form Page. 我尝试为注册按钮页面启动startActivity(),但是当我按回去时,它导航回到空的表单页面。

  Intent intent = new Intent(mActivity.getActivity(), RegisterButton.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        oActivity.getActivity().startActivity(intent);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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