scb998
scb998

Reputation: 909

Return to Home Activity after successfully sending email Android

My app allows the user to enter in information in various fields, take a photo, and then send all the information to a pre-determined email address.

Once they have sent the email, I would like to display a thank you message (probably via Toast) and then take them back to my Home Activity. To use iOS jargon, how do I perform a segue to another screen on successfully sending an email.

EDIT: I have attempted to implement the solution provided, but not my app is just moving to the next scene, and not sending the email. Have i implemented it incorrectly?

if (Witness_response == "Yes"){
                Intent emailIntent = new Intent(Intent.ACTION_SEND);
                emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Dob in a Hoon Report(Y)");
                emailIntent.putExtra(Intent.EXTRA_TEXT, "Hoon report has been recieved " + emailBody);
                emailIntent.setType("image/*");
                Uri uri = Uri.fromFile(f);
                emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
                emailIntent.setType("message/rfc822");
                startActivity(Intent.createChooser(emailIntent, "Choose email client..."));
                Intent ReturnIntent = new Intent(dob_in_a_hoon.this, HomeScreen.class );
                dob_in_a_hoon.this.startActivity(ReturnIntent);

Upvotes: 0

Views: 443

Answers (2)

emen
emen

Reputation: 6328

This snippet allows you to move from activity B to activity A:

    Intent i = new Intent(getApplicationContext(), HomeActivity.class);
    startActivity(i);

Or like ed209 said, you can go back to previous activity by calling onBackPressed method.

Upvotes: 0

ed209
ed209

Reputation: 838

That really depends on how your application is built, if it is built on fragment swapping you will want to load up the desired fragment. Otherwise you could start a new intent (Activity) like this

Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
myIntent.putExtra("key", value); //Optional parameters
CurrentActivity.this.startActivity(myIntent);

You could even get away with just calling onBackPressed which will take you back to the previous activity.

Upvotes: 1

Related Questions