How to send some data to fragment when it popped from backstack?

marioosh

I have one activity with container for fragments. Fragment1 is for example list of products. On search action, i replace container with Fragment2 (search-filter panel) and need on back-button send some data to popped from backstack Fragment1. How to do that ? I have static create method on all fragments (with setArguments use), but i don't want to create new instance. Maybe i've something missed in using of fragments, but know only about setArguments method, but this method is only usable to creating new instances of fragments.

A.S.

You could store the Data in the MainActivity and read it from any Fragment like:

//MainActivity
private String mSearchItem;

public void getSearchItem(){
    return this.mSearchItem;
}

public void setSearchItem(String searchItem){
    this.mSearchItem = searchItem;
}


//FRAGMENT 1
public void onResume(){
    super.onResume();

    String item = ((MainActivity)getActivity()).getSearchItem();
    //if item != null do some crazy shizzle
    //set MainActivity searchitem to null to avoid reloading it
}



//FRAGMENT 2
private void setData(String searchItem){
    ((MainActivity)getActivity()).setSearchItem(searchItem);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Detect if fragment is truly visible in OnResume when being popped from backstack

From Dev

Android - Blank fragment when returning from backstack

From Dev

How to navigate to last popped up fragment from next fragment?

From Java

How to resume Fragment from BackStack if exists

From Dev

How to send data from fragment to fragment within same fragment activity?

From Dev

How to send data from fragment to fragment within same fragment activity?

From Dev

Send data from Activity to Fragment when fragment is onCreateView

From Dev

Fragment is not removed from BackStack

From Dev

Get fragment from backstack

From Dev

Fragment is not removed from BackStack

From Dev

How to send data from Activity to Fragment

From Dev

how to send data from an activity back to a fragment

From Dev

How to send data from a fragment to an activity?

From Dev

How to send data from one Fragment to another Fragment?

From Dev

Android: How to send data from parent fragment to child fragment

From Dev

Android: How to send data from parent fragment to child fragment

From Dev

Android : Which method is called when fragment is pop out from backstack

From Dev

how to send data from activity to fragment when user clicks on back button in android?

From Dev

How to handle backstack for replacing the same fragment with different data

From Dev

How to send data from listview from one fragment to another

From Dev

Send Data from DialogFragment to Fragment

From Dev

Send data to fragment from Activity

From Dev

Send Data from a fragment to another fragment

From Dev

Objective - c How to get Data from popToRootViewController class, I have Text field in that class I want that textfield text when screen is popped

From Dev

Android how to send an Intent from a fragment when a RecyclerView item is clicked

From Dev

Android how to send an Intent from a fragment when a RecyclerView item is clicked

From Dev

Android - How to send data from main activity to loaded fragment

From Dev

How to send data from activity to the fragment for update a graph?

From Dev

How to send data from an activity to a Fragment in Android using interfaces?

Related Related

  1. 1

    Detect if fragment is truly visible in OnResume when being popped from backstack

  2. 2

    Android - Blank fragment when returning from backstack

  3. 3

    How to navigate to last popped up fragment from next fragment?

  4. 4

    How to resume Fragment from BackStack if exists

  5. 5

    How to send data from fragment to fragment within same fragment activity?

  6. 6

    How to send data from fragment to fragment within same fragment activity?

  7. 7

    Send data from Activity to Fragment when fragment is onCreateView

  8. 8

    Fragment is not removed from BackStack

  9. 9

    Get fragment from backstack

  10. 10

    Fragment is not removed from BackStack

  11. 11

    How to send data from Activity to Fragment

  12. 12

    how to send data from an activity back to a fragment

  13. 13

    How to send data from a fragment to an activity?

  14. 14

    How to send data from one Fragment to another Fragment?

  15. 15

    Android: How to send data from parent fragment to child fragment

  16. 16

    Android: How to send data from parent fragment to child fragment

  17. 17

    Android : Which method is called when fragment is pop out from backstack

  18. 18

    how to send data from activity to fragment when user clicks on back button in android?

  19. 19

    How to handle backstack for replacing the same fragment with different data

  20. 20

    How to send data from listview from one fragment to another

  21. 21

    Send Data from DialogFragment to Fragment

  22. 22

    Send data to fragment from Activity

  23. 23

    Send Data from a fragment to another fragment

  24. 24

    Objective - c How to get Data from popToRootViewController class, I have Text field in that class I want that textfield text when screen is popped

  25. 25

    Android how to send an Intent from a fragment when a RecyclerView item is clicked

  26. 26

    Android how to send an Intent from a fragment when a RecyclerView item is clicked

  27. 27

    Android - How to send data from main activity to loaded fragment

  28. 28

    How to send data from activity to the fragment for update a graph?

  29. 29

    How to send data from an activity to a Fragment in Android using interfaces?

HotTag

Archive