The method getApplicationContext() is undefined - fragment issues The method getApplicationContext() is undefined - fragment issues android android

The method getApplicationContext() is undefined - fragment issues


You can get the activity that contains the fragment with getActivity().

Therefore getActivity().getApplicationContext() would work.

getActivity().findViewById(int) would also work.

Make sure, though, you don't use getActivity() prior to onActivityCreated(), since it would return null prior to that.


Change

Intent intent = new Intent(getApplicationContext(), LoginActivity.class);

to

Intent intent = new Intent(getActivity(), LoginActivity.class);


you can access context from onAttach() like below example

 @Override    public void onAttach(@NonNull Context context) {        super.onAttach(context);    }