Clicking on the collapsed notification message app will restart











up vote
0
down vote

favorite












I have reviewed a lot of information on this issue, but no one can solved it.



On android 7.0 devices,when using NotificationManager to send more than 5 messages, all messages will be collapsed.



Please click on the image to see the message is collapsed.



When I click on this collapsed notification bar message, my app will be rebooted into the login activity even if my app is logged in and running in the foreground.This is terrible.If I click on a single notification bar message, then it will enter the activity normally.



How to set the notification bar message to not collapse or when I click on the collapsed notification bar message, do not restart the app.
this is my code:



Intent notifyIntent;
PendingIntent appIntent;
notifyIntent = new Intent(context, TestActivity.class);
notifyIntent.putExtra("content", contentJson);
appIntent = PendingIntent.getActivity(context,
noticeId, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "program").setAutoCancel(true)
.setSmallIcon(iconId)
.setContentTitle(notifyTitle)
.setDefaults(Notification.DEFAULT_ALL)
.setNumber(noticeId)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setGroupSummary(false)
.setContentIntent(appIntent);
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
builder.setColorized(true);
Notification myNoti = builder.build();
myNoti.flags = NotificationCompat.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL;
if (noticeId > 40) {
noticeId = 0;
notificationManager.cancelAll();
}
notificationManager.notify(noticeId, myNoti);


I set TestActivity



 android:launchMode="singleTop"









share|improve this question




























    up vote
    0
    down vote

    favorite












    I have reviewed a lot of information on this issue, but no one can solved it.



    On android 7.0 devices,when using NotificationManager to send more than 5 messages, all messages will be collapsed.



    Please click on the image to see the message is collapsed.



    When I click on this collapsed notification bar message, my app will be rebooted into the login activity even if my app is logged in and running in the foreground.This is terrible.If I click on a single notification bar message, then it will enter the activity normally.



    How to set the notification bar message to not collapse or when I click on the collapsed notification bar message, do not restart the app.
    this is my code:



    Intent notifyIntent;
    PendingIntent appIntent;
    notifyIntent = new Intent(context, TestActivity.class);
    notifyIntent.putExtra("content", contentJson);
    appIntent = PendingIntent.getActivity(context,
    noticeId, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "program").setAutoCancel(true)
    .setSmallIcon(iconId)
    .setContentTitle(notifyTitle)
    .setDefaults(Notification.DEFAULT_ALL)
    .setNumber(noticeId)
    .setPriority(NotificationCompat.PRIORITY_MAX)
    .setGroupSummary(false)
    .setContentIntent(appIntent);
    builder.setVisibility(Notification.VISIBILITY_PUBLIC);
    builder.setColorized(true);
    Notification myNoti = builder.build();
    myNoti.flags = NotificationCompat.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL;
    if (noticeId > 40) {
    noticeId = 0;
    notificationManager.cancelAll();
    }
    notificationManager.notify(noticeId, myNoti);


    I set TestActivity



     android:launchMode="singleTop"









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have reviewed a lot of information on this issue, but no one can solved it.



      On android 7.0 devices,when using NotificationManager to send more than 5 messages, all messages will be collapsed.



      Please click on the image to see the message is collapsed.



      When I click on this collapsed notification bar message, my app will be rebooted into the login activity even if my app is logged in and running in the foreground.This is terrible.If I click on a single notification bar message, then it will enter the activity normally.



      How to set the notification bar message to not collapse or when I click on the collapsed notification bar message, do not restart the app.
      this is my code:



      Intent notifyIntent;
      PendingIntent appIntent;
      notifyIntent = new Intent(context, TestActivity.class);
      notifyIntent.putExtra("content", contentJson);
      appIntent = PendingIntent.getActivity(context,
      noticeId, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "program").setAutoCancel(true)
      .setSmallIcon(iconId)
      .setContentTitle(notifyTitle)
      .setDefaults(Notification.DEFAULT_ALL)
      .setNumber(noticeId)
      .setPriority(NotificationCompat.PRIORITY_MAX)
      .setGroupSummary(false)
      .setContentIntent(appIntent);
      builder.setVisibility(Notification.VISIBILITY_PUBLIC);
      builder.setColorized(true);
      Notification myNoti = builder.build();
      myNoti.flags = NotificationCompat.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL;
      if (noticeId > 40) {
      noticeId = 0;
      notificationManager.cancelAll();
      }
      notificationManager.notify(noticeId, myNoti);


      I set TestActivity



       android:launchMode="singleTop"









      share|improve this question















      I have reviewed a lot of information on this issue, but no one can solved it.



      On android 7.0 devices,when using NotificationManager to send more than 5 messages, all messages will be collapsed.



      Please click on the image to see the message is collapsed.



      When I click on this collapsed notification bar message, my app will be rebooted into the login activity even if my app is logged in and running in the foreground.This is terrible.If I click on a single notification bar message, then it will enter the activity normally.



      How to set the notification bar message to not collapse or when I click on the collapsed notification bar message, do not restart the app.
      this is my code:



      Intent notifyIntent;
      PendingIntent appIntent;
      notifyIntent = new Intent(context, TestActivity.class);
      notifyIntent.putExtra("content", contentJson);
      appIntent = PendingIntent.getActivity(context,
      noticeId, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "program").setAutoCancel(true)
      .setSmallIcon(iconId)
      .setContentTitle(notifyTitle)
      .setDefaults(Notification.DEFAULT_ALL)
      .setNumber(noticeId)
      .setPriority(NotificationCompat.PRIORITY_MAX)
      .setGroupSummary(false)
      .setContentIntent(appIntent);
      builder.setVisibility(Notification.VISIBILITY_PUBLIC);
      builder.setColorized(true);
      Notification myNoti = builder.build();
      myNoti.flags = NotificationCompat.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL;
      if (noticeId > 40) {
      noticeId = 0;
      notificationManager.cancelAll();
      }
      notificationManager.notify(noticeId, myNoti);


      I set TestActivity



       android:launchMode="singleTop"






      android notifications






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 10:23









      Ali Khaki

      7111418




      7111418










      asked Nov 21 at 9:32









      bfther

      35




      35
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          I found the problem, not what I thought. App is not restarted.Only LoginActivity was recreated once and placed on the top of the stack.I am worried that other people have the same thoughts as me and think that the APP has been restarted,So I won’t change this question.I hope to help people who have this problem.I will put the solution below.



          When you click on the collapsed notification bar message, assume your LoginAtivity has been recreated.You need to write the following code in the onCreate of LoginActivity



           @Override
          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (!isTaskRoot()) {
          finish();
          return;
          }
          setContentView(R.layout.activity_main_menu);
          }


          isTaskRoot() will detect if this class is at the root of the stack.If not, then finish.



          Note that if you have logic in onDestory, use isTaskToot() to determine,for example:



          @Override
          protected void onDestroy(){
          super.onDestroy();
          if (isTaskRoot()) {
          //your code
          }
          }





          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',
            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%2f53408955%2fclicking-on-the-collapsed-notification-message-app-will-restart%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








            up vote
            0
            down vote













            I found the problem, not what I thought. App is not restarted.Only LoginActivity was recreated once and placed on the top of the stack.I am worried that other people have the same thoughts as me and think that the APP has been restarted,So I won’t change this question.I hope to help people who have this problem.I will put the solution below.



            When you click on the collapsed notification bar message, assume your LoginAtivity has been recreated.You need to write the following code in the onCreate of LoginActivity



             @Override
            protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (!isTaskRoot()) {
            finish();
            return;
            }
            setContentView(R.layout.activity_main_menu);
            }


            isTaskRoot() will detect if this class is at the root of the stack.If not, then finish.



            Note that if you have logic in onDestory, use isTaskToot() to determine,for example:



            @Override
            protected void onDestroy(){
            super.onDestroy();
            if (isTaskRoot()) {
            //your code
            }
            }





            share|improve this answer

























              up vote
              0
              down vote













              I found the problem, not what I thought. App is not restarted.Only LoginActivity was recreated once and placed on the top of the stack.I am worried that other people have the same thoughts as me and think that the APP has been restarted,So I won’t change this question.I hope to help people who have this problem.I will put the solution below.



              When you click on the collapsed notification bar message, assume your LoginAtivity has been recreated.You need to write the following code in the onCreate of LoginActivity



               @Override
              protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              if (!isTaskRoot()) {
              finish();
              return;
              }
              setContentView(R.layout.activity_main_menu);
              }


              isTaskRoot() will detect if this class is at the root of the stack.If not, then finish.



              Note that if you have logic in onDestory, use isTaskToot() to determine,for example:



              @Override
              protected void onDestroy(){
              super.onDestroy();
              if (isTaskRoot()) {
              //your code
              }
              }





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                I found the problem, not what I thought. App is not restarted.Only LoginActivity was recreated once and placed on the top of the stack.I am worried that other people have the same thoughts as me and think that the APP has been restarted,So I won’t change this question.I hope to help people who have this problem.I will put the solution below.



                When you click on the collapsed notification bar message, assume your LoginAtivity has been recreated.You need to write the following code in the onCreate of LoginActivity



                 @Override
                protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                if (!isTaskRoot()) {
                finish();
                return;
                }
                setContentView(R.layout.activity_main_menu);
                }


                isTaskRoot() will detect if this class is at the root of the stack.If not, then finish.



                Note that if you have logic in onDestory, use isTaskToot() to determine,for example:



                @Override
                protected void onDestroy(){
                super.onDestroy();
                if (isTaskRoot()) {
                //your code
                }
                }





                share|improve this answer












                I found the problem, not what I thought. App is not restarted.Only LoginActivity was recreated once and placed on the top of the stack.I am worried that other people have the same thoughts as me and think that the APP has been restarted,So I won’t change this question.I hope to help people who have this problem.I will put the solution below.



                When you click on the collapsed notification bar message, assume your LoginAtivity has been recreated.You need to write the following code in the onCreate of LoginActivity



                 @Override
                protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                if (!isTaskRoot()) {
                finish();
                return;
                }
                setContentView(R.layout.activity_main_menu);
                }


                isTaskRoot() will detect if this class is at the root of the stack.If not, then finish.



                Note that if you have logic in onDestory, use isTaskToot() to determine,for example:



                @Override
                protected void onDestroy(){
                super.onDestroy();
                if (isTaskRoot()) {
                //your code
                }
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 6:09









                bfther

                35




                35






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53408955%2fclicking-on-the-collapsed-notification-message-app-will-restart%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

                    Sphinx de Gizeh

                    Dijon

                    Équipe cycliste