0

I create an app in which I have to send mail from any of the mail clients available. Now I have to perform some tasks when the user comes back to my application from mail client. But I have no idea how to track the user when he came back from the mail client.

I also want to that- it is possible to track that does user send mail or not when he came back to my application.

the code I wrote for sending mail-

 Intent mailIntent = new Intent(Intent.ACTION_SEND);
            mailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"kavara.tech@gmail.com"});
            mailIntent.setType("message/rfc822");
            mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
            mailIntent.putExtra(Intent.EXTRA_TEXT, message);
            startActivity(Intent.createChooser(mailIntent, "Choose an Email client...")); 
Akshay Rajput
  • 250
  • 4
  • 11

1 Answers1

1

To implement a solution for your problem you can use the methods of activity lifecycle,such as onPause() and on onResume(),

onPause()- the code in onPause() will be executed when user leaves your application and opens the email client.

onResume()- the code inside onResume() will be executed when activity is created as well as when user re-enters to the activity after sending mail i.e user returns to your application

Have a look at this,

https://developer.android.com/guide/components/activities/activity-lifecycle

Prathamesh
  • 1,064
  • 1
  • 6
  • 16
  • 2
    Ok now I got the idea how I have to code for this and what about the second problem which is about the successfully send an email or not – Akshay Rajput Jun 07 '20 at 17:27
  • well as per my knowledge, there is no way you can figure out if a mail is sent or discarded or saved as draft.But have a look at this questions also https://stackoverflow.com/questions/3778048/how-can-we-use-startactivityforresult-for-email-intent, https://stackoverflow.com/questions/24006749/android-how-to-figure-out-if-email-was-sent-by-checking-sent-items – Prathamesh Jun 08 '20 at 13:34