Android app set to launcher when oncreate start two times problem

Source: Internet
Author: User

These days there is a need to set their own application to the form of launcher, set after the OnCreate will be launched two times, in the Internet to find the data after the screen set the result of the first said: In the mainacitivity set up Android: Configchanges= "MCC|MNC" can solve the problem.

Today, when I look at log, I find that Launcher activity is OnDestroy and then restarted.
Probable cause guessing:
1. Toggle Screen
MCC (mobile Country Code) and MNC (mobile network Code) caused by configuration changes such as 2.MCC MNC
Since the launcher was set to force horizontal screen, it should not cause a reboot.
A Android.intent.action.CONFIGURATION_CHANGED broadcast will be sent for the CONFIGURATION change system.
So I made a radio receiver to detect whether it was caused by a change in the configuration (later found that launcher itself had the radio)
It turns out that the MCC value is changed from 0 (undefined) to 460 (China)
The reason has been preliminarily determined, how can we let the activity do not restart it?
Since the activity is restarted, go ahead and see what the activity has to prevent the restart ....
Luck is really good, just have this attribute:
android:configchanges=["MCC", "MNC", "locale", "touchscreen", "keyboard", "Keyboardhidden", "Navigation", " Screenlayout "," Fontscale "," Uimode "," orientation "," screensize "," Smallestscreensize "]
The official explanation is this:
Lists configuration changes that the activity would handle itself. When a-configuration change occurs at runtime, the activity was shut down and restarted by default, but declaring a Configu Ration with this attribute would prevent the activity from being restarted. Instead, the activity remains running and itsonconfigurationchanged () method is called.
The General meaning is:
Whether the activity saves its own state when the configuration of the enumerated attributes changes. When the application has a configuration change, the activity will close and restart itself by default, but if this attribute is defined, the activity will not have to be restarted, it will remain running and call the Onconfigurationchanged () method at the same time. This means that when the android:configchanges= "MCC|MNC" is not configured, the activity is restarted when the value of the MCC or MNC changes, and onconfigurationchanged () is not called
If this property is configured, launcher activity will not start twice at boot time.

The above method I have tested is feasible.


Data from: http://www.th7.cn/Program/Android/201408/263797.shtml


Android app set to launcher when oncreate start two times problem

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.