Get current activity from fragment

后端 未结 2 1304
猫巷女王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:34

    Change below code

    new SendMailTask(MainActivity.this).execute(fromEmail,
                       fromPassword, toEmailList, emailSubject, emailBody);
    

    To

    new SendMailTask(getActivity()).execute(fromEmail,
                       fromPassword, toEmailList, emailSubject, emailBody);
    

    For more details you can check below link.

    Accessing the Activity from a Fragment

提交回复
热议问题