How to use setArguments() and getArguments() methods in Fragments?

Just call getArguments() in your Frag2‘s onCreateView() method:

public class Frag2 extends Fragment {
    
     public View onCreateView(LayoutInflater inflater,
         ViewGroup containerObject,
         Bundle savedInstanceState){
         //here is your arguments
         Bundle bundle=getArguments(); 
  
        //here is your list array 
        String[] myStrings=bundle.getStringArray("elist");   
     }
}

EDIT:

Best practice is read and save arguments in onCreate method. It’s worse to do it in onCreateView because onCreateView will be called each time when fragment creates view (for example each time when fragment pops from backstack)

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle arguments = getArguments(); 
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)