Q:

Cannot resolve finish() in intent in Fragment in Android Studio

Intent myIntent = new Intent(viewEnterChildExp.getContext(), MainActivityExpenses.class);
myIntent.putExtra("fromEnterChildExpenseToMainActivityExpenses", "true");
startActivity(myIntent);
finish();

I'm using the above code snippet in fragment
The finish() is in red color. 
When I put mouse cursor over it, an error is popped:
can resolve method finish()

TIA!

A:

Use getActivity().finish(); from Fragment to finish Activity in which current fragment is attached

A:

You have to use activity instance for finish it.
Call getActivity().finish()

