'Switch from fragment to activity in android studio

I made an application where I integrated the tabbed activity. In the tabbed activity I put 3 fragments. Now in the 3rd fragment I put a button and I want when I click on the button it redirects me to a new activity I did. I used an intent as we usually do between activities but it doesn't work. Need help please



Solution 1:[1]

use getContext instade of Activity.this. use the below code in your button to redirect from fragment to activity

yourButton.setOnClickListener(view -> {
            startActivity(new Intent(getContext(), Your_Activity.class));
        });

If the problem is not solved yet, let me know with logcat error.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 M Dev