getActivity() call causes RuntimeException: Could not launch intent Intent act=android.intent.action.MAIN

前端 未结 4 1157
走了就别回头了
走了就别回头了 2021-02-05 15:47

Updated #1: more info added to the end of this post

I\'m new to Android development and testing.

I have three Espresso tests. First test passes, but the

4条回答
  •  梦毁少年i
    2021-02-05 16:17

    This seems to work for me to close all of the activities in the stack except the first one.

       @After
       @Override
       public void tearDown() throws Exception
       {
          Intent intent = new Intent(getActivity(), getActivity().getClass());
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Removes other Activities from stack
          intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
          myActivity.startActivity(intent);
          super.tearDown();
    
       }
    

提交回复
热议问题