Android Activity Summary

Source: Internet
Author: User

/*----------------------------------------* * Description--activity Related content summary. *-describes--s1.activity's 7 life cycle *☆☆☆☆☆ Individual activity lifecycle: * 1.Activity created: onCreate () = OnStart () + Onresume () * 2. Press the HOME key or enter its He activities (lost focus): onPause () = OnStop () * 3. Re-entry (regain focus): Onrestart () = OnStart () + onresume () * 4. Exit: OnPause () = On Stop () = OnDestroy () * 5. Pop-up dialog (loses focus): No life cycle? * 6. Toggle: Horizontal = Vertical or reverse * re-walk life cycle onpause () = OnStop () + OnDestroy () ... onresume () * 7. Set the screen but never change the life cycle: Activit Y Add properties to the Register list * android:configchanges= "keyboardhidden|orientation|screensize" *☆☆☆☆ Activity 7 Life Cycle Description: *-1. void OnCreate (Bundle savedinstancestate) activity was created when *-2. void OnStart () activity becomes called when the user is visible on the screen. *-3. void Onresume () activity is invoked when it starts interacting with the user (whether it is starting or restarting A * activity, the method is always called). *-4. void OnPause () is called when activity is paused, which is used to save the active state, but also to protect the scene, press stack, etc. *-5. void OnStop () is called when activity is stopped and turned into an invisible phase and subsequent life-cycle events. *-6. void Onrestart () is called when activity is restarted. The activity is still in the stack, not the start of a new activity. *-7. void OnDestroy () activity is called when it is completely removed from system memory, the method called may be * Because someone calls the OnFinish () method directly or the system decides to stop the activity to free up resources *☆ Other related methods *-1. Window Focus Change onwindowfocuschanged (Boolean hasfocus) *-2. When system resources are low and When destroying an activity, the state information of the view is saved to the bundle Savedinstancestate * re-created and the parameters are loaded, which can be used for data saving operations such as screen orientation rotation * OnCreate (Bundle savedinstance       State) * Onsaveinstancestate (bundle outstate) * Onrestoreinstancestate (bundle savedinstancestate) * Reference: *http://blog.csdn.net/shulianghan/article/details/38297083 *      http://blog.sina.com.cn/s/blog_618199e60101g1k5.html *-Description--s2. Value and jump *☆☆ activity registration: Set Name property to package name + class name * -1.<activity android:name= ". Basic.dir.basic1.ModxBasic1Activity"/> * -2.label Property: The value is the activity display title android:label= "modxbasic1activity" *☆☆activity Jump: *-1. Jump from desktop icon to app * <intent-fi lter> * <action android:name= "Android.intent.action.MAIN"/> * <category android:name= "Andro Id.intent.category.LAUNCHER "/> * </intent-filter> *-2. Jump directly to the next activity of the app * Intent intent = new Intent ( Bactivity.this, Cactivity.class); * StartActivity (intent); *-3. Implicit intent to use an intent to jump to two applications already configured with this intent * Intent Intent = new Intent ("com.example.activity"); * StartActivity (intent); *      !! Registration required * <intent-filter> * <action android:name= "com.example.activity"/> * &L T;category android:name= "Android.intent.category.DEFAULT"/> * </intent-filter> *☆☆☆activity method of transmission *- 1. In the intent object, you can put in various data types * value values can be basic data types and strings, bundle objects, implement serializablePort or Parcelable Interface Object * Intent also encapsulates some methods of transmitting arrays, ArrayList collections * Intent.putextra ("key", Value) *-2. Create a bundle (packet) object, and then call The put method of the bundle object is used to store the data, * Finally, the bundle object is stored in the intent *!! The bundle object can be understood as a map key value pair * Bundle transmits the same data type as intent, but bundles encapsulate more methods * -3.startactivityforresult () value is the data exchange of two activities * a activity Start the next activity and add a request code, B receives the request code through the intent data back, and end B activity, * Complete data interaction. Use relative limitations, Trouble * A Startactivityforresult (intent,requestcode);       * Onactivityresult (int requestcode, int. ResultCode, Intent data) * B Setresult (resultcode,intent) return data * Finish () *-4. Use Global Object Application * 1). MyApplication extends Application; * 2). <application android:name= ".  MyApplication "Manifest Set properties * 3). getapplication get Application object, strong go myapplication, get variable * Strong turn Myapplication.xxx * -5. Third-Party encapsulation tool Eventbus *-describes--S3. Extends the life cycle of *☆☆☆ activities and fragment: *☆☆☆ activities and service lifecycles: The life cycle of *☆☆☆ activities and view drawing methods:--Description of the--s4.activity Dynamic mode * <!--android:launchmode= "Singletop" is not re-created at the top of the stack – <!--android:Launchmode= "SingleInstance" is in the task stack, only one instance of itself--* <!--android:launchmode= "Singletask" is not recreated, but the task on it is cleared-- * <!--android:launchmode= "standard" Each jump is re-created--* description--none. *-Describe--b1.none. *---------------------------------------------------------------------------*/
Activity common settings Q1. Set Activity full Screen/status bar-navigation bar transparency

Activity Full Screen @link

/*set it to is no title*/

Requestwindowfeature (Window.feature_no_title);

/*set it to being full screen*/

GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN);

Status bar-navigation bar background transparent @link

        //Hide title barrequestwindowfeature (Window.feature_no_title); View Root= Layoutinflater.from ( This). Inflate (R.layout.activity_main,NULL); //or add android:fitssystemwindows= "true" to the root layer of the interface.//This property allows the content interface to start from below the status bar. Viewcompat.setfitssystemwindows (Root,true);        Setcontentview (root); if(Build.VERSION.SDK_INT >=Build.version_codes. LOLLIPOP) {//Android 5.0 + Full Transparencywindow window =GetWindow (); Window.clearflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS|WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); Window.getdecorview (). setsystemuivisibility (View.system_ui_flag_layout_fullscreen|view.system_ui_flag_layout_hide_navigation|view.system_ui_flag_layout_stable);            Window.addflags (WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //status bar (above several lines of code must, refer to Setstatusbarcolor|setnavigationbarcolor method source)Window.setstatusbarcolor (color.transparent); //Virtual navigation keysWindow.setnavigationbarcolor (color.transparent); } Else if(Build.VERSION.SDK_INT >=Build.version_codes. KITKAT) {//Android 4.4 + Translucentwindow window =GetWindow (); //status Barwindow.addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //Virtual navigation keyswindow.addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); }
Q2. Preferenceactivity

preferenceactivity UI Components

Checkboxpreference

Radio Box

Switchpreference

Switch options

Edittextpreference

Text Input Box options

Ringtonepreference

Ringtone Options

Listpreference

list box

Multiselectlistpreference

Check list box

Preferencecategory

Combo box

Basic Properties and methods:

public attribute: Android:defaultvalue= "false"//Default Valueandroid:key= "Check_box_preference_1"//equivalent to IDandroid:title= "Check Box preference"//titleAndroid:summary= "AAA"//OverviewAndroid:persistent= "true"//indicates whether the value corresponding to the preference element is written to the Sharedpreferen fileAndroid:dependency= "Check_box_preference_0"//indicates that a preference (denoted by a) has a usable state that relies on another preference (denoted by B)listpreference/MultiSelectListPreference:android:entries= "@array/list_preference_entries"//List Contentsandroid:entryvalues= "@array/list_preference_entries"//List contents corresponding valuesEvent://Setting a Change eventCheckboxpreference1.setonpreferencechangelistener (NewPreference.onpreferencechangelistener () {@Override Public BooleanOnpreferencechange (Preference Preference, Object newvalue) {LOGUTILS.E (newvalue.tostring ()); return true; }        });//Basic MethodsListpreference1.setsummary ("str");        Listpreference1.getsummary (); Listpreference1.setvalue ("");        Listpreference1.getvalue ();        Listpreference1.setentries ();        Listpreference1.getentry ();        Listpreference1.setentryvalues ();        Listpreference1.getentryvalues ();        Listpreference1.settitle ();        Listpreference1.gettitle ();        Listpreference1.seticon (); Listpreference1.geticon ();//Click eventsCheckboxpreference1.setonpreferenceclicklistener (NewPreference.onpreferenceclicklistener () {@Override Public BooleanOnpreferenceclick (Preference Preference) {return true; }        });

Other methods

Sharedpreferences Setting changes

Sharedpreferences.registeronsharedpreferencechangelistener (listener);

New API

The version is higher than Android 3.0 (API 10), can be displayed in normal activity using preferencefragment, or you can use preferenceactivity. Link

Reference:

Preferenceactivity developer.android

Basic use of Android Preferenceactivity

Use of preference in Android and Monitoring event analysis API Analysis

Android Combat Skills VI: preferenceactivity Use of detailed examples

Q3. Activity Manifest Property Configuration

Other methods

Set app to switch to background in recent projects not visible link

Android:excludefromrecents= "true"

Android Activity Summary

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.