Removing launcher activity from stack on pendingIntent
I have some issue. When my app not in the background (removed from recent) everything works fine. But when my app is in the recent and then I open "ResponseActivity" via notification pending intent, on back click at "ResponseActivity" I getting to my MainActivity (Launcher activity).
I've added FLAG_ACTIVITY_NEW_TASK but it not seem to do it.
Intent intent = new Intent(this, ResponseActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.addAction(0, "Other", pendingIntent)
.setLargeIcon(getCircleBitmap(bitmap))
.setContentTitle(userDB.getName())
.setContentText(smallText)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setColor(getResources().getColor(R.color.colorPrimary))
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = mNotificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);
channel.setDescription("");
channel.enableLights(true);
channel.setLightColor(Color.RED);
channel.enableVibration(true);
mNotificationManager.createNotificationChannel(channel);
}
mNotificationManager.notify(1000, mBuilder.build());
Manifest:
<application
android:name=".ApplicationContextProvider"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyFirebaseInstanceService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name=".MainActivity" />
<activity android:name=".LoginActivity" />
<activity android:name="verification.MyVerifyPhoneActivity" />
<activity android:name=".ResponseActivity"
android:theme="@style/AppTheme2">
</activity>
</application>
android android-pendingintent
add a comment |
I have some issue. When my app not in the background (removed from recent) everything works fine. But when my app is in the recent and then I open "ResponseActivity" via notification pending intent, on back click at "ResponseActivity" I getting to my MainActivity (Launcher activity).
I've added FLAG_ACTIVITY_NEW_TASK but it not seem to do it.
Intent intent = new Intent(this, ResponseActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.addAction(0, "Other", pendingIntent)
.setLargeIcon(getCircleBitmap(bitmap))
.setContentTitle(userDB.getName())
.setContentText(smallText)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setColor(getResources().getColor(R.color.colorPrimary))
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = mNotificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);
channel.setDescription("");
channel.enableLights(true);
channel.setLightColor(Color.RED);
channel.enableVibration(true);
mNotificationManager.createNotificationChannel(channel);
}
mNotificationManager.notify(1000, mBuilder.build());
Manifest:
<application
android:name=".ApplicationContextProvider"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyFirebaseInstanceService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name=".MainActivity" />
<activity android:name=".LoginActivity" />
<activity android:name="verification.MyVerifyPhoneActivity" />
<activity android:name=".ResponseActivity"
android:theme="@style/AppTheme2">
</activity>
</application>
android android-pendingintent
Please post your manifest in the question.
– David Wasser
Nov 22 '18 at 14:33
Thank you, added it.
– Dim
Nov 22 '18 at 20:36
add a comment |
I have some issue. When my app not in the background (removed from recent) everything works fine. But when my app is in the recent and then I open "ResponseActivity" via notification pending intent, on back click at "ResponseActivity" I getting to my MainActivity (Launcher activity).
I've added FLAG_ACTIVITY_NEW_TASK but it not seem to do it.
Intent intent = new Intent(this, ResponseActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.addAction(0, "Other", pendingIntent)
.setLargeIcon(getCircleBitmap(bitmap))
.setContentTitle(userDB.getName())
.setContentText(smallText)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setColor(getResources().getColor(R.color.colorPrimary))
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = mNotificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);
channel.setDescription("");
channel.enableLights(true);
channel.setLightColor(Color.RED);
channel.enableVibration(true);
mNotificationManager.createNotificationChannel(channel);
}
mNotificationManager.notify(1000, mBuilder.build());
Manifest:
<application
android:name=".ApplicationContextProvider"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyFirebaseInstanceService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name=".MainActivity" />
<activity android:name=".LoginActivity" />
<activity android:name="verification.MyVerifyPhoneActivity" />
<activity android:name=".ResponseActivity"
android:theme="@style/AppTheme2">
</activity>
</application>
android android-pendingintent
I have some issue. When my app not in the background (removed from recent) everything works fine. But when my app is in the recent and then I open "ResponseActivity" via notification pending intent, on back click at "ResponseActivity" I getting to my MainActivity (Launcher activity).
I've added FLAG_ACTIVITY_NEW_TASK but it not seem to do it.
Intent intent = new Intent(this, ResponseActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_background)
.addAction(0, "Other", pendingIntent)
.setLargeIcon(getCircleBitmap(bitmap))
.setContentTitle(userDB.getName())
.setContentText(smallText)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setColor(getResources().getColor(R.color.colorPrimary))
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = mNotificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID);
channel.setDescription("");
channel.enableLights(true);
channel.setLightColor(Color.RED);
channel.enableVibration(true);
mNotificationManager.createNotificationChannel(channel);
}
mNotificationManager.notify(1000, mBuilder.build());
Manifest:
<application
android:name=".ApplicationContextProvider"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyFirebaseInstanceService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name=".MainActivity" />
<activity android:name=".LoginActivity" />
<activity android:name="verification.MyVerifyPhoneActivity" />
<activity android:name=".ResponseActivity"
android:theme="@style/AppTheme2">
</activity>
</application>
android android-pendingintent
android android-pendingintent
edited Nov 22 '18 at 20:35
Dim
asked Nov 21 '18 at 14:57
DimDim
1,09665497
1,09665497
Please post your manifest in the question.
– David Wasser
Nov 22 '18 at 14:33
Thank you, added it.
– Dim
Nov 22 '18 at 20:36
add a comment |
Please post your manifest in the question.
– David Wasser
Nov 22 '18 at 14:33
Thank you, added it.
– Dim
Nov 22 '18 at 20:36
Please post your manifest in the question.
– David Wasser
Nov 22 '18 at 14:33
Please post your manifest in the question.
– David Wasser
Nov 22 '18 at 14:33
Thank you, added it.
– Dim
Nov 22 '18 at 20:36
Thank you, added it.
– Dim
Nov 22 '18 at 20:36
add a comment |
1 Answer
1
active
oldest
votes
If you want to be sure that only ResponseActivity
is in the stack when you select the Notification, you can do this:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
instead of:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
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%2f53414780%2fremoving-launcher-activity-from-stack-on-pendingintent%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
If you want to be sure that only ResponseActivity
is in the stack when you select the Notification, you can do this:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
instead of:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
add a comment |
If you want to be sure that only ResponseActivity
is in the stack when you select the Notification, you can do this:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
instead of:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
add a comment |
If you want to be sure that only ResponseActivity
is in the stack when you select the Notification, you can do this:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
instead of:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
If you want to be sure that only ResponseActivity
is in the stack when you select the Notification, you can do this:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
instead of:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
answered Nov 25 '18 at 18:20
David WasserDavid Wasser
70.2k10143202
70.2k10143202
add a comment |
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%2f53414780%2fremoving-launcher-activity-from-stack-on-pendingintent%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
Please post your manifest in the question.
– David Wasser
Nov 22 '18 at 14:33
Thank you, added it.
– Dim
Nov 22 '18 at 20:36