Reputation: 25174
I have a background service BGService
, it displays an Activity BGServActivity
when certain event occurs. I have override onBackPressed to finish the displayed Activity BGServActivity
.
Suppose, UI of Application App_XYZ
is currently displaying. And my service BGService
is triggered by the event and BGServActivity
is displayed. And When i press back it closes the current Activity BGServActivity
and displays the previous UI from Application App_XYZ
.
But i want the UI from App_XYZ
to be sent to background when i start BGServActivity
from my BGService
.
My question is
Is there any special flag or something that i can do to send the previously displaying UI from another activity to sent to background before starting My BGServActivity
from My service BGService
.
Upvotes: 1
Views: 2241
Reputation: 25174
I think i got solution.
First show the HOME Screen as goto10's solution
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Then-after open my Activity BGServActivity
Intent i = new Intent();
i.setClass(getBaseContext(), BGServActivity.class);
Bundle b = new Bundle();
b.putBoolean("IS_FROM_SERVICE", true);
//add extras
i.putExtras(b);
startActivity(i);
And its working... :D
Upvotes: 0
Reputation: 4370
If you want to force the user to go to the Home screen when your Activity closes, you can do this:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I advise against this though. The standard behavior when closing an activity should be to return to the previously viewed activity.
Upvotes: 2