Get current activity from fragment

后端 未结 2 1303
猫巷女王i
猫巷女王i 2021-02-19 05:37

I have this class for sending email with android

    public class SendMailTask extends AsyncTask {

    private ProgressDialog statusDialog;
    private Activity         


        
2条回答
  •  心在旅途
    2021-02-19 06:25

    From fragment to activity use this :

    ((YourActivityName)getActivity()).yourPublicMethod();
    

    From activity to fragment use this :

    FragmentManager fragmentManager = getSupportFragmentManager();
    //include fragment via layout xml
    YourFragmentClass fragment = (YourFragmentClass)fragmentManager.findFragmentById(R.id.your_fragment_id);
    fragment.yourPublicMethod();
    

提交回复
热议问题