title: How to pass data from Activity to fragment using OnFragmentInteractionListener
body: <p>I have Main activity and it have 3 fragments inside tab layout. i have to call api from activity and pass data to all three fragments after successfull response. After data passed i have to show data inside fragment. How it can be done through <code>OnFragmentInteractionListener</code>? </p>
  
  <p><strong>Default created fragment</strong></p>
  
  <pre><code>class StudentDetails : Fragment() {
  
  private var listener: OnFragmentInteractionListener? = null
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      arguments?.let {
  
      }
  }
  
  override fun onCreateView(
      inflater: LayoutInflater, container: ViewGroup?,
      savedInstanceState: Bundle?
  ): View? {
      val view = inflater.inflate(R.layout.fragment_student_details, container, false)
  
      return view
  }
  
  
  override fun onAttach(context: Context) {
      super.onAttach(context)
      if (context is OnFragmentInteractionListener) {
          listener = context
      } else {
          throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
      }
  }
  
  
  
  interface OnFragmentInteractionListener {
      fun onFragmentInteraction(name:String,phone:String){
      }
  }
  
  companion object {
  
      @JvmStatic
      fun newInstance() =
          StudentDetails().apply {
              arguments = Bundle().apply {
  
              }
          }
  }
  }
  </code></pre>
  
  <p><strong>Activity</strong></p>
  
  <pre><code>class StudentDetailActivity : AppCompatActivity(),StudentDetails.OnFragmentInteractionListener {
      override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_student_detail)
        .....
  
        setupViewPager()
      }
  
      private fun setupViewPager(){
      val adapter = StudentDetailsViewPager(supportFragmentManager)
  
      val firstFragment : StudentDetails = StudentDetails.newInstance()
      val secondFragment : StudentDetails = StudentDetails.newInstance()
      val thirdFragment : StudentDetails = StudentDetails.newInstance()
  
      adapter.addFragment(firstFragment,"Student")
      adapter.addFragment(secondFragment,"Class")
      adapter.addFragment(thirdFragment,"Fees")
  
      val viewPager = view_pager
  
      viewPager.adapter = adapter
      tabs.setupWithViewPager(viewPager)
  }
  
       private fun getStudentDetails(student_id : String?){
      val inst_id = SharedPreferenceManager(this).getInstituteId()
      RetrofitClientCommon.client.create(StudentApi::class.java).getStudentDetails(student_id!!,inst_id!!).enqueue(object : Callback&lt;com.digimkey.digimke.Institute.models.StudentDetails&gt;{
          override fun onFailure(
              call: Call&lt;com.digimkey.digimke.Institute.models.StudentDetails&gt;,
              t: Throwable
          ) {
              Toast.makeText(this@StudentDetailActivity,t.message,Toast.LENGTH_SHORT).show()
          }
  
          override fun onResponse(
              call: Call&lt;com.digimkey.digimke.Institute.models.StudentDetails&gt;,
              response: Response&lt;com.digimkey.digimke.Institute.models.StudentDetails&gt;
          ) {
              if (response.isSuccessful){
                  val res = response.body() as com.digimkey.digimke.Institute.models.StudentDetails
                  val phone = res.phone
  
                  onFragmentInteraction(name,phone!!)
              }else{
                  val error = response.errorBody()!!.string()
                  Toast.makeText(this@StudentDetailActivity,error,Toast.LENGTH_SHORT).show()
              }
          }
  
      })
  }
  
  override fun onFragmentInteraction(name:String,phone:String) {
  
  }
  }
  </code></pre>