Start a new Activity from Fragment

前端 未结 7 1988
遇见更好的自我
遇见更好的自我 2020-12-05 08:09

Using Android Studio, I have my MainActiviy class with a Placeholder fragment. This fragment has buttons, but one has to load an Activity. How does one do this? I was tol

相关标签:
7条回答
  • 2020-12-05 08:46

    You should use getActivity() to launch an Activity from Fragment.

    From a Fragment: Context is parent activity (getActivity()).

    Intent intent = new Intent(getActivity(), AnotherActivity.class);
    startActivity(intent);
    
    0 讨论(0)
提交回复
热议问题