[Bug encounter] android service does not go onDestroy

[Phenomena] 

    Activity A starts service in onCreat() to start the custom service and Activity A calls finish to destroy it.

    In the custom service, do nothing but print a log and display a notification bar in the key method. After clicking the notification bar, open Activity B.

    There is a stop button in Activity B to stopservice.

Do you feel that this scene is very simple, such a magical phenomenon appears, how to click the stop button, the custom service does not go to the onDestroy callback.


【analyze】 


    This is the insecurity that android brings to the development process! Everything is so simple! This pit has tossed me all morning! It made me start to doubt my life!!!


[Correction] 

    Delay the finish timing of calling Activity A.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326996098&siteId=291194637