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.
Asked
Active
Viewed 71 times
0
-
Try using `intent` to reopen your home activity after sending email. – Eslam El-Meniawy Jan 24 '16 at 07:18
-
Just finish() the activity after sending the email if its an activity which is opened by home activity – Pankaj Jan 24 '16 at 07:19
2 Answers
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));
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
-
1At least add a few comments to explain what you are doing and why it works. Thank you. – skypjack Jan 24 '16 at 10:15