What is the best way to finish() an activity from a foreground service without bringing the app to the foreground?How to exit an Android app programmatically?How to bring an Activity to foreground (or create if not existing)?PendingIntent continues to fire on activity reloadIntent not picked up by singleTop Activitycan't call onNewIntentHow to open dialog styled activity from notification without previous activity closing?Activity's onDestroy is called instead of onResume when bringing the app to foreground from recent listNotification to bring Activity into foreground only if it is in backgroundPendingIntent launches different activity of the app packageIs there a way to bring an application to foreground on push notification receive?Stop Android foreground service using notification when app is not in background
Do the Shadow Magic sorcerer's Strength of the Grave feature and the half-orc's Relentless Endurance trait work together?
Is pointing finger in meeting consider bad?
Interview was just a one hour panel. Got an offer the next day; do I accept or is this a red flag?
Will users know a CardView is clickable
Are athletes' college degrees discounted by employers and graduate school admissions?
Why can't we feel the Earth's revolution?
Am I being scammed by a sugar daddy?
Manager wants to hire me; HR does not. How to proceed?
How can religions without a hell discourage evil-doing?
How can I detect if I'm in a subshell?
Opposite of "Concerto Grosso"?
Why are backslashes included in this shell script?
Can an escape pod land on Earth from orbit and not be immediately detected?
My players want to use called-shots on Strahd
What is the color associated with lukewarm?
Does "aurea" have the second meaning?
Would a bit of grease on overhead door cables or bearings cause the springs to break?
Why is it bad to use your whole foot in rock climbing
Is there a term for someone whose preferred policies are a mix of Left and Right?
My parents claim they cannot pay for my college education; what are my options?
Background for black and white chart
How can I find out about the game world without meta-influencing it?
Is all-caps blackletter no longer taboo?
I sent an angry e-mail to my interviewers about a conflict at my home institution. Could this affect my application?
What is the best way to finish() an activity from a foreground service without bringing the app to the foreground?
How to exit an Android app programmatically?How to bring an Activity to foreground (or create if not existing)?PendingIntent continues to fire on activity reloadIntent not picked up by singleTop Activitycan't call onNewIntentHow to open dialog styled activity from notification without previous activity closing?Activity's onDestroy is called instead of onResume when bringing the app to foreground from recent listNotification to bring Activity into foreground only if it is in backgroundPendingIntent launches different activity of the app packageIs there a way to bring an application to foreground on push notification receive?Stop Android foreground service using notification when app is not in background
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to build an app that can be used for calling.
My CallActivity
is declared singleTop
in the manifest file. I have a foreground service (CallService
) which is started as soon as the app goes to the background while the user is on a call, since the device must not sleep during a call.
The notification for my CallService
allows the user to either resume the call or hangup. My goal is to have the user press a button on the notification and hangup the ongoing call without bringing the app to the foreground.
I have tried using PendingIntent.getActivity()
to start the CallActivity once the app is in background, from the CallService. But I have not been able to hangup the call yet. Here is some code...
Intent returnToCallIntent = new Intent(this, CallActivity.class);
PendingIntent returnPendingIntent = PendingIntent.getActivity(this, 0, returnToCallIntent, 0);
Intent hangUpCallIntent = new Intent(this, CallActivity.class);
hangUpCallIntent.putExtra("ACTION_FINISH_ACTIVITY", true);
PendingIntent hangUpPendingIntent = PendingIntent.getActivity(this, 0, hangUpCallIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Right now both pending intents resolve to the same action which is hanging up the call while bring the app to the foreground. I figured out that this is happening because the 2 intents only differ in their extras and hence android does not distinguish them, i.e. intent#filterEquals()
does not see any difference between them.
But the more important question is how can I finish()
the CallActivity
and have it pop off the backstack silently, without bringing it to the foreground. Also, after the CallActivity
has been stopped, I need to stop the CallService
in the background. So when the user taps the app in the recents screen, she/he should see the activity which was prior to the CallActivity
on the backstack.
PS: Logic to hang up the call has been done in onNewIntent()
method in CallActivity
.
android android-activity android-service android-pendingintent
add a comment |
I am trying to build an app that can be used for calling.
My CallActivity
is declared singleTop
in the manifest file. I have a foreground service (CallService
) which is started as soon as the app goes to the background while the user is on a call, since the device must not sleep during a call.
The notification for my CallService
allows the user to either resume the call or hangup. My goal is to have the user press a button on the notification and hangup the ongoing call without bringing the app to the foreground.
I have tried using PendingIntent.getActivity()
to start the CallActivity once the app is in background, from the CallService. But I have not been able to hangup the call yet. Here is some code...
Intent returnToCallIntent = new Intent(this, CallActivity.class);
PendingIntent returnPendingIntent = PendingIntent.getActivity(this, 0, returnToCallIntent, 0);
Intent hangUpCallIntent = new Intent(this, CallActivity.class);
hangUpCallIntent.putExtra("ACTION_FINISH_ACTIVITY", true);
PendingIntent hangUpPendingIntent = PendingIntent.getActivity(this, 0, hangUpCallIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Right now both pending intents resolve to the same action which is hanging up the call while bring the app to the foreground. I figured out that this is happening because the 2 intents only differ in their extras and hence android does not distinguish them, i.e. intent#filterEquals()
does not see any difference between them.
But the more important question is how can I finish()
the CallActivity
and have it pop off the backstack silently, without bringing it to the foreground. Also, after the CallActivity
has been stopped, I need to stop the CallService
in the background. So when the user taps the app in the recents screen, she/he should see the activity which was prior to the CallActivity
on the backstack.
PS: Logic to hang up the call has been done in onNewIntent()
method in CallActivity
.
android android-activity android-service android-pendingintent
System.exit(1);
See How to exit an Android app programmatically?
– Jon Goodwin
Mar 25 at 1:57
Thanks @JonGoodwin butSystem.exit()
seems to be a bit harsh. I tried the solution suggested by @David Wasser below and it seems to work well.
– pendingIntent
Mar 25 at 14:45
System.exit()
is definitely not what you want. Android interprets that as "your app crashed".
– David Wasser
Mar 25 at 15:27
add a comment |
I am trying to build an app that can be used for calling.
My CallActivity
is declared singleTop
in the manifest file. I have a foreground service (CallService
) which is started as soon as the app goes to the background while the user is on a call, since the device must not sleep during a call.
The notification for my CallService
allows the user to either resume the call or hangup. My goal is to have the user press a button on the notification and hangup the ongoing call without bringing the app to the foreground.
I have tried using PendingIntent.getActivity()
to start the CallActivity once the app is in background, from the CallService. But I have not been able to hangup the call yet. Here is some code...
Intent returnToCallIntent = new Intent(this, CallActivity.class);
PendingIntent returnPendingIntent = PendingIntent.getActivity(this, 0, returnToCallIntent, 0);
Intent hangUpCallIntent = new Intent(this, CallActivity.class);
hangUpCallIntent.putExtra("ACTION_FINISH_ACTIVITY", true);
PendingIntent hangUpPendingIntent = PendingIntent.getActivity(this, 0, hangUpCallIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Right now both pending intents resolve to the same action which is hanging up the call while bring the app to the foreground. I figured out that this is happening because the 2 intents only differ in their extras and hence android does not distinguish them, i.e. intent#filterEquals()
does not see any difference between them.
But the more important question is how can I finish()
the CallActivity
and have it pop off the backstack silently, without bringing it to the foreground. Also, after the CallActivity
has been stopped, I need to stop the CallService
in the background. So when the user taps the app in the recents screen, she/he should see the activity which was prior to the CallActivity
on the backstack.
PS: Logic to hang up the call has been done in onNewIntent()
method in CallActivity
.
android android-activity android-service android-pendingintent
I am trying to build an app that can be used for calling.
My CallActivity
is declared singleTop
in the manifest file. I have a foreground service (CallService
) which is started as soon as the app goes to the background while the user is on a call, since the device must not sleep during a call.
The notification for my CallService
allows the user to either resume the call or hangup. My goal is to have the user press a button on the notification and hangup the ongoing call without bringing the app to the foreground.
I have tried using PendingIntent.getActivity()
to start the CallActivity once the app is in background, from the CallService. But I have not been able to hangup the call yet. Here is some code...
Intent returnToCallIntent = new Intent(this, CallActivity.class);
PendingIntent returnPendingIntent = PendingIntent.getActivity(this, 0, returnToCallIntent, 0);
Intent hangUpCallIntent = new Intent(this, CallActivity.class);
hangUpCallIntent.putExtra("ACTION_FINISH_ACTIVITY", true);
PendingIntent hangUpPendingIntent = PendingIntent.getActivity(this, 0, hangUpCallIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Right now both pending intents resolve to the same action which is hanging up the call while bring the app to the foreground. I figured out that this is happening because the 2 intents only differ in their extras and hence android does not distinguish them, i.e. intent#filterEquals()
does not see any difference between them.
But the more important question is how can I finish()
the CallActivity
and have it pop off the backstack silently, without bringing it to the foreground. Also, after the CallActivity
has been stopped, I need to stop the CallService
in the background. So when the user taps the app in the recents screen, she/he should see the activity which was prior to the CallActivity
on the backstack.
PS: Logic to hang up the call has been done in onNewIntent()
method in CallActivity
.
android android-activity android-service android-pendingintent
android android-activity android-service android-pendingintent
asked Mar 25 at 1:31
pendingIntentpendingIntent
31
31
System.exit(1);
See How to exit an Android app programmatically?
– Jon Goodwin
Mar 25 at 1:57
Thanks @JonGoodwin butSystem.exit()
seems to be a bit harsh. I tried the solution suggested by @David Wasser below and it seems to work well.
– pendingIntent
Mar 25 at 14:45
System.exit()
is definitely not what you want. Android interprets that as "your app crashed".
– David Wasser
Mar 25 at 15:27
add a comment |
System.exit(1);
See How to exit an Android app programmatically?
– Jon Goodwin
Mar 25 at 1:57
Thanks @JonGoodwin butSystem.exit()
seems to be a bit harsh. I tried the solution suggested by @David Wasser below and it seems to work well.
– pendingIntent
Mar 25 at 14:45
System.exit()
is definitely not what you want. Android interprets that as "your app crashed".
– David Wasser
Mar 25 at 15:27
System.exit(1);
See How to exit an Android app programmatically?– Jon Goodwin
Mar 25 at 1:57
System.exit(1);
See How to exit an Android app programmatically?– Jon Goodwin
Mar 25 at 1:57
Thanks @JonGoodwin but
System.exit()
seems to be a bit harsh. I tried the solution suggested by @David Wasser below and it seems to work well.– pendingIntent
Mar 25 at 14:45
Thanks @JonGoodwin but
System.exit()
seems to be a bit harsh. I tried the solution suggested by @David Wasser below and it seems to work well.– pendingIntent
Mar 25 at 14:45
System.exit()
is definitely not what you want. Android interprets that as "your app crashed".– David Wasser
Mar 25 at 15:27
System.exit()
is definitely not what you want. Android interprets that as "your app crashed".– David Wasser
Mar 25 at 15:27
add a comment |
1 Answer
1
active
oldest
votes
You can have your Activity
register an anonymous BroadcastReceiver
that listens for a specific broadcast Intent
. When your Service
wants to finish the Activity
, it can just send the broadcast Intent
that the Activity
is listening for.
In onReceive()
of the BroadcastReceiver
, just call finish()
. This won't bring the Activity
to the foreground.
1
Thank you @David Wasser. The solution works really well. Unfortunately my upvote will not reflect until I get more reputation :(
– pendingIntent
Mar 25 at 14:48
You can accept the answer by clicking the green checkmark next to the answer. That will help others with a similar problem. It will also get the question off the list of unanswered questions, as well as giving me some reputation points.
– David Wasser
Mar 25 at 15:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330262%2fwhat-is-the-best-way-to-finish-an-activity-from-a-foreground-service-without-b%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can have your Activity
register an anonymous BroadcastReceiver
that listens for a specific broadcast Intent
. When your Service
wants to finish the Activity
, it can just send the broadcast Intent
that the Activity
is listening for.
In onReceive()
of the BroadcastReceiver
, just call finish()
. This won't bring the Activity
to the foreground.
1
Thank you @David Wasser. The solution works really well. Unfortunately my upvote will not reflect until I get more reputation :(
– pendingIntent
Mar 25 at 14:48
You can accept the answer by clicking the green checkmark next to the answer. That will help others with a similar problem. It will also get the question off the list of unanswered questions, as well as giving me some reputation points.
– David Wasser
Mar 25 at 15:26
add a comment |
You can have your Activity
register an anonymous BroadcastReceiver
that listens for a specific broadcast Intent
. When your Service
wants to finish the Activity
, it can just send the broadcast Intent
that the Activity
is listening for.
In onReceive()
of the BroadcastReceiver
, just call finish()
. This won't bring the Activity
to the foreground.
1
Thank you @David Wasser. The solution works really well. Unfortunately my upvote will not reflect until I get more reputation :(
– pendingIntent
Mar 25 at 14:48
You can accept the answer by clicking the green checkmark next to the answer. That will help others with a similar problem. It will also get the question off the list of unanswered questions, as well as giving me some reputation points.
– David Wasser
Mar 25 at 15:26
add a comment |
You can have your Activity
register an anonymous BroadcastReceiver
that listens for a specific broadcast Intent
. When your Service
wants to finish the Activity
, it can just send the broadcast Intent
that the Activity
is listening for.
In onReceive()
of the BroadcastReceiver
, just call finish()
. This won't bring the Activity
to the foreground.
You can have your Activity
register an anonymous BroadcastReceiver
that listens for a specific broadcast Intent
. When your Service
wants to finish the Activity
, it can just send the broadcast Intent
that the Activity
is listening for.
In onReceive()
of the BroadcastReceiver
, just call finish()
. This won't bring the Activity
to the foreground.
answered Mar 25 at 10:41
David WasserDavid Wasser
71.6k11148207
71.6k11148207
1
Thank you @David Wasser. The solution works really well. Unfortunately my upvote will not reflect until I get more reputation :(
– pendingIntent
Mar 25 at 14:48
You can accept the answer by clicking the green checkmark next to the answer. That will help others with a similar problem. It will also get the question off the list of unanswered questions, as well as giving me some reputation points.
– David Wasser
Mar 25 at 15:26
add a comment |
1
Thank you @David Wasser. The solution works really well. Unfortunately my upvote will not reflect until I get more reputation :(
– pendingIntent
Mar 25 at 14:48
You can accept the answer by clicking the green checkmark next to the answer. That will help others with a similar problem. It will also get the question off the list of unanswered questions, as well as giving me some reputation points.
– David Wasser
Mar 25 at 15:26
1
1
Thank you @David Wasser. The solution works really well. Unfortunately my upvote will not reflect until I get more reputation :(
– pendingIntent
Mar 25 at 14:48
Thank you @David Wasser. The solution works really well. Unfortunately my upvote will not reflect until I get more reputation :(
– pendingIntent
Mar 25 at 14:48
You can accept the answer by clicking the green checkmark next to the answer. That will help others with a similar problem. It will also get the question off the list of unanswered questions, as well as giving me some reputation points.
– David Wasser
Mar 25 at 15:26
You can accept the answer by clicking the green checkmark next to the answer. That will help others with a similar problem. It will also get the question off the list of unanswered questions, as well as giving me some reputation points.
– David Wasser
Mar 25 at 15:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330262%2fwhat-is-the-best-way-to-finish-an-activity-from-a-foreground-service-without-b%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
System.exit(1);
See How to exit an Android app programmatically?– Jon Goodwin
Mar 25 at 1:57
Thanks @JonGoodwin but
System.exit()
seems to be a bit harsh. I tried the solution suggested by @David Wasser below and it seems to work well.– pendingIntent
Mar 25 at 14:45
System.exit()
is definitely not what you want. Android interprets that as "your app crashed".– David Wasser
Mar 25 at 15:27