Android: An open key raises the issue!!

Source: Internet
Author: User

1. Introduction to the problem

First describe the problem, when we install the app, the interface will display two buttons, a completion key, an open key, click the Open key, enter the application. At this point, we click the Home button, the program will be backstage. Then click on the app icon on the desktop, a huge bug appears: The app will restart! Instead of onresume! the original interface If your app is not sensitive to multiple launches, this is fine, but if your app is sensitive to multiple launches, you have to deal with it.

2. Solution

First analysis of the cause of the problem, in the current Android system (the latest 4.4.3), click the Open button and click on the icon to start, the intent parameters are not the same, the activation mode of the activity is different, resulting in the above problems. However, because the startup parameters are set by the system, we do not change. Then we have two ideas:

1. The second start, the first start to kill

2. On the second boot, wake the activity for the first start and turn it off the second time.

Generally we choose the second type, so we have the following ideas:

1. When starting the first activity, determine whether the startup mode is started by clicking the Open key.

2. Register Broadcastreceiver in the activity that needs to be awakened, and after receiving the broadcast, call your own Onresume method.

The code added to the first activity's OnCreate method is as follows:

@Overrideprotected void OnCreate (Bundle savedinstancestate) {    super.oncreate (savedinstancestate);    if (Getintent (). GetFlags () & intent.flag_activity_brought_to_front)! = 0) {        //Send broadcast here, wake up ACTIVITY        before activation Finish ();        return;    }    Regular Activity creation Code ...}


The problem has been solved perfectly.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.