Im trying to run an activity from a button press in a fragment, however the app crashes when the button is pressed.
public class FitnessFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_fitness, container, false);
Button btn1 = (Button) root
.findViewById(R.id.trackCalories);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getActivity(), video_activity.class);
((MainActivity) getActivity()).startActivity(intent);
}
});
return root;
}
}
I'm currently struggling to grasp the concept of launching activities from fragments, any help would be appreciated.