Android 4.4.2 - java.lang.RuntimeException: Performing stop of activity that is not resumed

后端 未结 4 1201
梦如初夏
梦如初夏 2020-12-02 10:00

I\'m getting this exception on a 4.4.2 device. Not reproducible on Android 4.3 device or lower.

Setup is I have a home activity (subclass of support ActionBarA

相关标签:
4条回答
  • 2020-12-02 10:35

    Just call the onResume super method before launching the new activity:

    super.onResume();
    
    0 讨论(0)
  • 2020-12-02 10:42

    I was getting this exception even when using onResume(), so I ended up overriding onPostResume() and starting activity from there, and the exception is gone. Not sure if this is an ideal solution, but still...

    0 讨论(0)
  • 2020-12-02 10:50

    That doesn't seem right to me. The splash activity would now be the top activity in the stack, so the HomeActivity onStop lifecycle method would get called eventually. Coincidentally, I moved the startActivity call for the splash activity from onCreate to onResume in the HomeActivity, and the error goes away.

    0 讨论(0)
  • 2020-12-02 10:50

    This issue will still be present on all high-end phones with Android 4.4.2 and above including NEXUS 5 and Samsumg s4 since onResume gets called but it is still in animation stage.So if you try to start a activity in onResume the issue will replicate.

    Put your switching activity in a handler delayed method.

        Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                  //Start another Activity Here
    
                default:
                    break;
            }
            return false;
        }
    });
    

    And in onResume call this.

     handler.sendEmptyMessageDelayed(1, 1000);
    

    By that time you can show loader or something or block user Interaction

    0 讨论(0)
提交回复
热议问题