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

前端 未结 6 914
太阳男子
太阳男子 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条回答
  •  旧巷少年郎
    2020-12-08 10:13

    Ok, this issue is resolved. To get access to the context before getActivity() has been called you need to call this function:

    Context context = this.getInstrumentation().getTargetContext().getApplicationContext();
    

提交回复
热议问题