Here is what I use to trigger method on MainActvity.java from my Fragment page:
((MainActivity) getActivity()).openGallery();
Once I get to slide in the fragment page for the first time after opening app, and execute this code, IT WORKS. But, when I hide that fragment page and then bring it back, and execute that code again, the app crashes, saying something like:
Attempt to invoke virtual method 'void com.test.test7.MainActivity.openGallery()' on a null object reference
None of the answers I found cover this problem, when it works for the first time and the crashes at the second time.
Any help is apreciated.