I will try to explain the cenario.
Look this image 1:
I have one Fragment called HOME with a toolbar.
In that Fragment i have a ViewPager with 2 fragments:
Fragment A and Fragment B
When the fragment A is activy, the toolbar has a action button that call another activity.
In that "another activity" i have a ViewPager with 2 fragments: Fragment C and Fragment D.
What i need is, when i click on a button inside Fragment C, the "another activity" closes and execute a callback inside Fragment A.
I tried with startActivityforresult but without sucess.
Tried too wiht a public interface inside fragment C that is implemented by fragment A, but i think this does not work like intended.
Anyone can give me a tip?
And sorry my english, not my native language.
Some code to explain:
Inside Fragment A
When the button inside toolbar is clicked him call "Another activity"
startActivityForResult(IAddPedido, RESULT_ADD);
The "another activity" create the viewpager and setup 2 fragments:
fragManager = getSupportFragmentManager();
adapterPedidosAdd = new AdapterPedidosAdd(fragManager);
// Seto adaptador passando o Id
viewPagerPedAdd.setAdapter(adapterPedidosAdd);
tLayoutPedAdd.post(new Runnable() {
@Override
public void run() {
tLayoutPedAdd.setupWithViewPager(viewPagerPedAdd);
}
});
Inside fragment C, when i click on "button" him will call set the result and call "finish()".
// Get the "another activity" and set the result
getActivity().setResult(1);
// Close the "another activity"
getActivity().finish();
And then, inside Fragment A i have the "onActivityResult":
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
But the "onActivityResult" inside Fragment A is never called.
Maybe i have to create "onActivityResult" inside "Home" and then, get the instance of fragment A to call a methode inside him?
PS.: The "Home" is aready an fragment, because i have a NavigationDrawer.