Android Application Resources

Source: Internet
Author: User

Reference style attributes

? [<Package_name >:] [<resource_type>/] <resource_name>

Apply the specified property value under the current topic
<Edittext id = "text"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: textcolor = "? Android: textcolorsecondary"
Android: text = "@ string/hello_world"/>

Capture runtime configuration changes

Configuration changes such as screen orientation, keyboard validity, and language usually cause android to restart the running activity (ondestroy is called, followed by oncreate ).
1. Use the following methods to save data:

// Onretainnonconfigurationinstance is called between onstop and ondestory.

// The mydataobject object cannot contain any data (drawable, adapter, and view) associated with the context to prevent memory leakage.

// Unavailable bundle. Bundle needs to be serialized and deserialized when saving the status of large data volumes, which consumes a lot of memory and may slow down the configuration change process.
@ Override
Public object onretainnonconfigurationinstance (){
Final mydataobject DATA = collectmyloadeddata ();
Return data;
}

 

@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );

Final mydataobject DATA = (mydataobject) getlastnonconfigurationinstance ();
If (Data = NULL ){
Data = loadmydata ();
}
...
}

2. You can also declare that you can capture the configuration changes during the runtime to prevent the Android system from restarting the activity.
<Activity Android: Name = ". myactivity"
Android: configchanges = "orientation | keyboardhidden"
Android: Label = "@ string/app_name">
When the declared runtime configuration changes, the onconfigurationchanged event will be received.

// When the configuration of an unspecified runtime changes, Android will restart the running activity
@ Override
Public void onconfigurationchanged (configuration newconfig ){
Super. onconfigurationchanged (newconfig );

// Checks the orientation of the screen
If (newconfig. Orientation = configuration. orientation_landscape ){
Toast. maketext (this, "Landscape", Toast. length_short). Show ();
} Else if (newconfig. Orientation = configuration. orientation_portrait ){
Toast. maketext (this, "portrait", Toast. length_short). Show ();
}
// Checks whether a hardware keyboard is available
If (newconfig. hardkeyboardhidden = configuration. hardkeyboardhidden_no ){
Toast. maketext (this, "keyboard visible", Toast. length_short). Show ();
} Else if (newconfig. hardkeyboardhidden = configuration. hardkeyboardhidden_yes ){
Toast. maketext (this, "keyboard hidden", Toast. length_short). Show ();
}
}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.