Accessing application context from TestSuite in Setup() before calling getActivity()

前端 未结 6 912
太阳男子
太阳男子 2020-12-08 09:42

I have an Activity that pulls an object from an Application extended class (application context) from within the OnCreate() method.

6条回答
  •  萌比男神i
    2020-12-08 10:27

    Always use this.getInstrumentation().getTargetContext() to access the context of the application.

    this.getInstrumentation().getTargetContext().getApplicationContext() is not same as this.getInstrumentation().getTargetContext()

    I was running the automation in 4.0.X versions and most of the time getApplicationContext() was returning null context.

提交回复
热议问题