Removing launcher activity from stack on pendingIntent












1















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>









share|improve this question

























  • 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
















1















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>









share|improve this question

























  • 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














1












1








1








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>









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 20:35







Dim

















asked Nov 21 '18 at 14:57









DimDim

1,08665496




1,08665496













  • 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











  • 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












1 Answer
1






active

oldest

votes


















1














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





share|improve this answer























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









    1














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





    share|improve this answer




























      1














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





      share|improve this answer


























        1












        1








        1







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





        share|improve this answer













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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 18:20









        David WasserDavid Wasser

        68.9k10139200




        68.9k10139200






























            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%2f53414780%2fremoving-launcher-activity-from-stack-on-pendingintent%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?