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;








0















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.










share|improve this question






















  • 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

















0















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.










share|improve this question






















  • 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













0












0








0








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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(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
















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












1 Answer
1






active

oldest

votes


















0














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.






share|improve this answer


















  • 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











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
);



);













draft saved

draft discarded


















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









0














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.






share|improve this answer


















  • 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















0














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.






share|improve this answer


















  • 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













0












0








0







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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












  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현