android– 如何在将活动发送到后台后重新获得活动的访问权限

android– 如何在将活动发送到后台后重新获得活动的访问权限,第1张

概述使用Espresso,我尝试使用Home按钮测试将活动发送到后台,然后再次将其放到前台进行一些检查:@EspressoTestpublicvoidtest(){onSomeView().check(matches(isDisplayed()));getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_HOME);Contextcontext=g

使用Espresso,我尝试使用Home按钮测试将活动发送到后台,然后再次将其放到前台进行一些检查:

@EspressoTestpublic voID test() {    onSomeVIEw().check(matches(isdisplayed()));    getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_HOME);    Context context = getInstrumentation().getTargetContext();    Intent intent = new Intent(context, MainActivity.class);    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    context.startActivity(intent);    onSomeVIEw().check(matches(isdisplayed()));}

我不得不使用intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);这是一个异常所暗示的,但除此之外我还测试过,启动它作为启动器活动,或使用
FLAG_ACTIVITY_REORDER_TO_FRONT,但视图不可见.即使测试通过.

解决方法:

Please consIDer this response as it works 100% when you want to
goBackgroundByClickingHomeThenGetBackToTheApp.

UIDevice device = UIDevice.getInstance(getInstrumentation());        device.pressHome();        device.pressRecentApps();        device.findobject(new UiSelector().text(getTargetContext().getString(getTargetContext().getApplicationInfo().labelRes)))                .click();

总结

以上是内存溢出为你收集整理的android – 如何在将活动发送到后台后重新获得活动的访问权限全部内容,希望文章能够帮你解决android – 如何在将活动发送到后台后重新获得活动的访问权限所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1116600.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存