0

I have created a "Button" in android studio to send emails. When I click it, it sends an email as intended, but does not then return to the "Home" activity.

peak
  • 105,803
  • 17
  • 152
  • 177
Eli
  • 827
  • 1
  • 7
  • 21

2 Answers2

0

You can use finish(); method, but it's not recommended.

See: How to finish current activity in Android

http://developer.android.com/guide/components/processes-and-threads.html#Threads

But, this is my suggestion, you should be able to after clicking the Button, then clear the activity and restart it(or you can do something like Gmail App and doing some stuffs after clicking):

Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
                                        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                        startActivity(i);

Also you can use:

Intent m = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(m);

Or:

startActivity(new Intent(FirstActivity.this, SecondActivity.class));
Community
  • 1
  • 1
ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
0
Intent intent = new Intent(context, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
Ashutosh Verma
  • 328
  • 1
  • 5