0

I am in a fragment which is a feedback form. When the user clicks on the button it takes the data from the form and passes it to an e-mail program that gets open after the user chooses it from the list after startActivity(intent).

My problem is, I am not sure if there is a way to get feedback to know when the 3rd party mailer is done or if the launcher is cancelled.

Also in my example, if you click the submit and then click on the gmail and then click send in gmail and close it out, it brings you back to the app with all the data still on the form.

I would like to switch fragments to a thank you fragment. I did experiment and was happy that if you click on a different icon int the bottom nav bar and go back to the feedback fragment that all the data is cleared out.

Thank you and all help would be appreciative. Shawn Mulligan

P.S. There is no code as I don't feel it is needed, I just need to know what direction to go into and any code snippetts if available to do the next step. change fragments after intent.

Srinivasan Sekar
  • 2,049
  • 13
  • 22
Shawn Mulligan
  • 103
  • 1
  • 8
  • Are you using an Intent chooser? If so, I think this [post](https://stackoverflow.com/questions/32203230/how-to-tell-which-app-was-selected-by-intent-createchooser) can help you. – jbmcle Jun 25 '19 at 03:10
  • I'm not intentionally using a chooser, the chooser is happening on it's own after the startActivity(intent) is called. I posted the actual code that calls the intent. Thanks – Shawn Mulligan Jun 25 '19 at 03:17
  • I looked at them solutions that you referenced and in all of the code there is nothing after the start of the intent. – Shawn Mulligan Jun 25 '19 at 03:25
  • 1
    I assume that you are familiar with `onActivityResult`. In my opinion that is what you need in order to know whether the user has sent feedback or not. – jbmcle Jun 25 '19 at 03:53
  • I did not know about the onActivityResult or startActivityForResult. I added my newly written code and I still am not getting the results that I thought I would be getting. – Shawn Mulligan Jun 25 '19 at 04:59

2 Answers2

0
 public void sendFeedbackMessage(String subject, String message) {

        Intent messageIntent = new Intent(android.content.Intent.ACTION_SENDTO);
        messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        messageIntent.setType("plain/text");
        messageIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
        messageIntent.setData(Uri.parse("mailto:foo@gmail.com"));
        startActivity(messageIntent);
        }
Shawn Mulligan
  • 103
  • 1
  • 8
0
startActivityForResult(messageIntent,1000);
    }

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data){
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK){
            if (requestCode == 1000){
                Toast.makeText(getContext().getApplicationContext(),"You sent mail",Toast.LENGTH_SHORT).show();
            }
        }else{
            Toast.makeText(getContext().getApplicationContext(),"Mail Not Sent",Toast.LENGTH_SHORT).show();
            }
        }

So I looked into startActivityForResult and onActivityResult and changed my code to the above. However it is doing nothing but Mail Not Sent. I did find out that gmail for one does not support this. I am totally fine with this, but shouldn't the chooser itself return something so that way the app would know if an app was chosen or the cancel or back button was used?

Shawn Mulligan
  • 103
  • 1
  • 8