Reputation: 129
I have a form in fragment A, after the user enters their information and presses on submit, they should get redirected to fragment B.
I can manage to call the fragment method, however I'm getting a NullPointerException error:
Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
How I am calling the method in fragment B:
(new FragmentB()).infoSubmitted();
How could I effectively call the method in fragment B?
Upvotes: 0
Views: 43
Reputation: 689
You can do that way, but it isn't good approach.
Once you submit form in FragmentA, return results to Activity and then start FragmentB.
In FragmentA it would be like:
public void formSubmitted(){
getActivity().startFragmentB(mFormData)
}
And in Activivity create a method:
public void startFragmentB(Form formData){
// handle fromData
// start fragmentB
}
Upvotes: 1