The problem of restarting the app after switching the Android program to the background and then clicking the desktop icon to enter

I believe that many apps today will do some code rewriting for the return key of the main page, some are pressing twice to exit, while others are returning to the system desktop like WeChat and QQ (that is, letting the program enter the background, at this time the program is not blocked. System kill), and then click the desktop icon to make the program go back to the previous home page again. In the past two days, the company's project has also requested to do so. However, a very strange problem was found in the actual test process: when the user installs with the installation package, it will prompt the user whether to complete or open it. When the user clicks to complete, there is no problem. When I clicked to open, I found that after pressing back or home to return to the desktop, and then clicking the desktop icon to enter the app, it started from the welcome page again , so I found a solution after consulting some information. For details, please refer to: http:/ /blog.csdn.net/busjb/article/details/40891239

 

The specific solution is to add the following code to the onCreate method of the started activity:

if((getIntent().getFlags()&Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)!=0){
            //end your activity
            finish();
            return;
        }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326445756&siteId=291194637