当前位置:网站首页>How many of the 36 difficult points of activity do you know?, Android interview 2020
How many of the 36 difficult points of activity do you know?, Android interview 2020
2022-06-24 00:18:00 【Ordinary netizens】
Preface
- learn
AndroidIt's been a while , Always focused on learning new things , Recently I found that a lot of things that are seldom used are forgotten , Take advantage of these two days , I'm going toActivityIn the form of questions , It's also for you to check the defects and make up the omissions .
In this paper , I will change my habit of blogging , Full text
XMindPresent all knowledge points in the form of mind map , Welcome to eat ~~
List of articles
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-QHgA2dEJ-1637978600673)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab263bcee1cb?imageView2/0/w/1280/h/960/ignore-error/1)]
Convenient for everyone to learn , I am here GitHub Create a Warehouse
Update warehouse content and blog synchronously . Because I am
Rare earth digs goldSimple booksCSDNBlog GardenEtc , All have new content . So you can directly focus on the warehouse , Don't miss the highlights !Warehouse address : Super dry ! Elaborate induction
Android、JVM、 Algorithm etc. , Old fellow iron supports. ! Give me one Star !
Divine plan
- Before we start , Let's have a look at
AndroidOfactivityWhat are the things ? - Borrow a very popular picture on the Internet to show you
Activity
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-JiZh91hf-1637978600718)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab263d2eccd9?imageView2/0/w/1280/h/960/ignore-error/1)]
One 、 Life cycle
- Post a famous picture first
- Let's first look at the specific method callbacks in the life cycle , One by one :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-cD9Ev7RH-1637978600719)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab263d483f3c?imageView2/0/w/1280/h/960/format/png/ignore-error/1)]
1.1 Dialog When it pops up
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-17SS6rVL-1637978600720)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2640bfa92b?imageView2/0/w/1280/h/960/ignore-error/1)]
- If it is simply created
dialog,ActivityMethods that do not perform the lifecycle - But if it's a jump to a not full screen
ActivityWords , Of course, it is carried out according to the normal life cycle - namely
onPasue()->onPause()( The original will not be executedActivityOfonStop(), Otherwise, the previous page will not display )
1.2 When switching between horizontal and vertical screens
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-dmKaWmyK-1637978600721)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2640d09989?imageView2/0/w/1280/h/960/ignore-error/1)]
Not set up
ActivityOfandroid:configChangeswhen , Cutting the screen will recall each life cycle , It will be executed once when cutting the horizontal screen , When cutting the vertical screen, it will execute twiceSet up
ActivityOfandroid:configChanges="orientation"when , Cutting the screen will still recall each life cycle , Cut across 、 It will only be executed once when the screen is upSet up
ActivityOfandroid:configChanges="orientation|keyboardHidden"when , Cutting the screen will not recall each life cycle , Only executeonConfigurationChangedMethodBe careful : And a little bit more , It's very important , One
AndroidDetails of changes ! WhenAPI >12when , Need to addscreenSizeattribute , Otherwise, the screen will switch even if you setorientationThe system will be rebuiltActivity!Execution of life cycle of horizontal and vertical screen switching
1.3 In different scenes Activity The changing process of life cycle
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-jEGNXCqT-1637978600722)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2662135b32?imageView2/0/w/1280/h/960/ignore-error/1)]
- start-up
Activity:onCreate()—>onStart()—>onResume(),ActivityEnter the running state . - When locking the screen, it will execute
onPause()andonStop(), When you open the screen, you should executeonStart()onResume()
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-wxXTpsJv-1637978600723)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2662bc3f51?imageView2/0/w/1280/h/960/ignore-error/1)]
ActivityBack office : At presentActivityGo to newActivityInterface or pressHomeKey back to main screen :onPause()—>onStop(), Enter stagnation state .ActivityBack to the front desk :onRestart()—>onStart()—>onResume(), Return to operation again .ActivityBack office : And the system is out of memory , The system will kill the background stateActivity, If we go back to thisActivity, Then I will goonCreate()-->onStart()—>onResume()
1.4 Will a Activity Set to window style
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-UmROzvvo-1637978600723)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2666b5baec?imageView2/0/w/1280/h/960/ignore-error/1)]
Just for us Activity Configure the following properties . android:theme="@android:style/Theme.Dialog"
1.5 Exit called multiple Activity Of Application
- Usually, the user exits a
ActivityJust press the back key , We write code to exitactivityCall directlyfinish()The method will do .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-mRyAqNdm-1637978600724)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2668399456?imageView2/0/w/1280/h/960/ignore-error/1)]
- Send specific broadcast :
- When you need to end the app , Send a specific broadcast , Every
ActivityAfter receiving the broadcast , close that will do . - To someone
activityIntention to register for broadcastregisterReceiver(receiver, filter) - If you've ever received close
activityBroadcast ofactivity finish()fall
- Recursive exit
- Just call
finish()Method Put the currentActivitysign out - Opening new
ActivityWhen usingstartActivityForResult, And then add your own logo , stayonActivityResultIn dealing with , Recursive close .
- Actually
- It can also be done through
intentOfflagTo achieveintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)Activate a newactivity. - At this time, if the task stack already has the
Activity, So the system willActivityAll of the aboveActivitykill . - In fact, it's equivalent to giving
ActivityThe configured startup mode issingleTask.
- Record open
Activity
- Every time you open one
Activity, Just record it . - When you need to exit , Close each one
Activity
1.6 Lock screen and unlock screen ,Activity How to execute a lifecycle
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-aMOQpERw-1637978600724)(https://user-gold-cdn.xitu.io/2019/10/30/16e1b5f0ff6a9d15?imageView2/0/w/1280/h/960/ignore-error/1)]
- When locking the screen, it will execute
onPause()andonStop(), When you open the screen, you should executeonStart()onResume()
1.7 modify Activity Enter and exit animation
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-sE06Pvt6-1637978600725)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2666eae897?imageView2/0/w/1280/h/960/ignore-error/1)]
- There are two ways , First, by definition
ActivityThe theme of , The second is through rewritingActivityOfoverridePendingTransitionMethod . - By setting the theme style in
styles.xmlEdit code in , add tothemes.xmlfile : stayAndroidManifest.xmlSpecified inActivityAppointtheme. - overwrite
overridePendingTransitionMethod :overridePendingTransition(R.anim.fade, R.anim.hold);
1.8 Activity Four states
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-q3bp1il7-1637978600725)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26844b8ee7?imageView2/0/w/1280/h/960/ignore-error/1)]
runnig: Users can click ,activityOn top of stack .paused:activityWhen you lose focus , By a non full screenactivityTo occupy or be possessed by a transparentactivityCover , In this stateactivityNot destroyed , All of its state information and member variables still exist , Just can't be clicked .( Memory crunch , ThisactivityCould be recycled )
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-59AoZD9z-1637978600726)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2687e2a13a?imageView2/0/w/1280/h/960/ignore-error/1)]
stopped: ThisactivityBy anotheractivityFull coverage , But thisactivityAll state information and member variables for are still present ( Except for the memory crunch )killed: ThisactivityHas been destroyed , All of its state information and member variables no longer exist .
1.9 How to handle exception exit
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-AUgNWLqU-1637978600726)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab268bcbf377?imageView2/0/w/1280/h/960/ignore-error/1)]
ActivityWhen you exit abnormally -->onPause()-->onSaveInstanceState()-->onStop()-->onDestory()- It should be noted that
onSaveInstanceState()Methods andonPauseThere's no strict sequence , Are likely toonPauseBefore , It is also possible to call after it , But it will be there.onStop()Call before method - Restart the
Activity-->onCreate()-->onStart()-->onRestoreInstanceState()-->onResume()
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-EibX9emP-1637978600727)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab268c50ae91?imageView2/0/w/1280/h/960/ignore-error/1)]
- Understand the execution of this life cycle, and then you can answer , First of all, you need to know what the interviewer means : Is to restart and restore this
ActivityOr just quit the whole thingapp - If you want to recover, you need to
onSaveInstanceState()To save the data inonRestoreInstanceState()Recovery in - If you want to exit
appSo we need to capture the global exception information , And exitapp - Of course, the personal suggestion is to use
UncaughtExceotionHandlerTo catch global exceptions and exitappThe operation of , This will reduce the legacy of previous crashes !
1.10 What is? onNewIntent
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-62q7F7Ii-1637978600727)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26900d9292?imageView2/0/w/1280/h/960/ignore-error/1)]
If
IntentActivityAt the top of the task stack , That is to say, it was opened beforeActivity, Now inonPause、onStopIn terms of state , Resend other appsIntentWordsThe order of execution is :
onNewIntent,onRestart,onStart,onResume.
Two 、 Boot mode
2.1 Boot mode
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-DhpcFeNY-1637978600728)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2695ac3863?imageView2/0/w/1280/h/960/ignore-error/1)]
ActivityThere are fourlaunchMode:standard、singleTop、singleTask、singleInstance.
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-oec1MGe6-1637978600728)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26af18ff50?imageView2/0/w/1280/h/960/ignore-error/1)]
StandardPattern ( The default mode )
explain : One at a time
ActivityWill create a new instance to be pushed again , Whether this instance exists or not .Life cycle : Every instance created
Activity's life cycle is typical , itsonCreate、onStart、onResumeWill be called .give an example : here
ActivityThere areA、B、CThreeActivity, here C At the top of the stack , The startup mode isStandardPattern . If inC ActivityAdd click event to , You need to jump to the same type ofC Activity. It turns out there's another oneC ActivityEnter the stack , Become the top of the stack .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-aflIXLrW-1637978600729)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26af2f73ef?imageView2/0/w/1280/h/960/ignore-error/1)]
SingleTopPattern ( Stack top reuse mode )
explain : There are two ways to deal with it : What needs to be created
ActivityWhen already at the top of the stack , At this time, the top of the stack will be reused directlyActivity. No more newActivity; To createActivityNot at the top of the stack , A new one will be created againActivityPush , Same asStandardModel as .Life cycle : In case I
ActivityWhen directly reused , itsonCreate、onStartNot called by the system , Because it didn't change . But a new wayonNewIntentWill be recalled (ActivityThis method will not be called back when it is created normally ).give an example : here
ActivityThere areA、B、CThreeActivity, hereCAt the top of the stack , The startup mode isSingleTopPattern . Situation 1 : stayC ActivityAdd click event to , You need to jump to the same type ofC Activity. The result is a direct reuse of the top of the stackC Activity. Situation two : stayC ActivityAdd click event to , You need to jump to another oneA Activity. The result is a newActivityPush . Become the top of the stack .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-VPhueTLm-1637978600729)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26b234a4cb?imageView2/0/w/1280/h/960/ignore-error/1)]
SingleTaskPattern ( In stack reuse mode )
explain : To create
ActivityWhen already on the stack , New will not be created at this timeActivity, It's going to be on the stackActivityThe others aboveActivityAll destruction , Make it the top of the stack .If you start it in another application , Then a new
task, And in time task Start thisActivity,singleTaskAllow something elseActivityIt's not in onetaskCo existing in , in other words , If I were heresingleTaskOpen a newActivity, This newActivityStill will be insingleTaskInstancetaskin .Life cycle : Same as
SingleTopThe same in pattern one . Just another callbackActivityMediumonNewIntentMethodgive an example : here
ActivityThere areA、B、CThreeActivity. hereCAt the top of the stack , The startup mode isSingleTaskPattern . Situation 1 : stayC ActivityAdd click event to , You need to jump to the same type ofC Activity. The result is a direct use of the top of the stackC Activity. Situation two : stayC ActivityAdd click event to , You need to jump to another oneA Activity. The result is thatA ActivityaboveB、CAll destruction , sendA ActivityBecome the top of the stack .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Ra1krKIV-1637978600729)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26b197fba4?imageView2/0/w/1280/h/960/ignore-error/1)]
SingleInstancePattern ( Single instance mode )
explain :
SingleInstanceA special , It's global singleton mode , It's a kind of reinforcementSingleTaskPattern . It has all its features , A little bit stronger : There is only one example , And this instance runs independently in ataskin , ThistaskThis is the only example , Nothing else is allowedActivityThere is .This is often used in system applications , such as
Launch、 Application of lock screen key, etc , There is only one in the whole system ! So in our application, we usually don't use . Just know .give an example : example
A ActivityIt's the mode , start-upAafter . The system will create a separate task stack for it , Due to the characteristics of stack reuse . No new requests will be createdActivity, Unless this unique task stack is destroyed by the system .
2.2 How to use startup mode
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-LGm9ep9A-1637978600730)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26b281455b?imageView2/0/w/1280/h/960/ignore-error/1)]
- stay
Manifest.xmlIt is specified inActivityBoot mode
- A static specifying method
- stay
Manifest.xmlThe document statesActivityAt the same time, specify its startup mode - In this way, when you jump in the code, you will create... According to the specified pattern
Activity.
- start-up
Activitywhen . stayIntentTo createActivity
- A dynamic startup mode
- stay
newOneIntentafter - adopt
IntentOfaddFlagsMethod to dynamically specify a startup mode .
- Be careful : Both of the above methods can be
ActivitySpecify startup mode , But there is a difference between them .
priority : Dynamic assignment means that the other priority is higher than the first one , If both exist at the same time , In another way .
Limit the scope : The first method cannot be
ActivityDirect designationFLAG_ACTIVITY_CLEAR_TOPidentification , The other way is not toActivityAppointsingleInstancePattern .
2.3 Practical application scenario of startup mode
Of the four modes
StandardPattern is the most common , Nothing special . andSingleInstanceMode is a singleton mode of the whole system , In our application, it will not be applied to . therefore , Here is the specific explanationSingleTopandSingleTaskApplication scenario of the mode :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-rpWNWrIi-1637978600730)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26b65bb92a?imageView2/0/w/1280/h/960/ignore-error/1)]
SingleTaskApplication scenario of the mode
- The most common application scenario is to keep only one of our applications open
ActivityExample . - The most typical example is the home page displayed in the application (
Homepage ). - Suppose the user jumps to another page on the home page , Want to return to the home page after running multiple operations , Suppose you don't use
SingleTaskPattern , In the process of clicking back, you will see the home page many times , This is obviously the design is unreasonable .
SingleTopApplication scenario of the mode
- Suppose you are in the current
ActivityAnd start the same type ofActivity - This type is recommended
ActivityThe startup mode of is specified asSingleTop, Can reduce Activity The creation of , Save memory !
- Be careful : Reuse
ActivityLife cycle callback for
- There's one more thing to consider here
ActivityThe problem of carrying page parameters in jump . - Because when a
ActivitySet upSingleTopperhapsSingleTaskAfter the model , Jump hereActivityReuse of existingActivitysituations , thisActivityOfonCreateMethod will not run again .onCreateMethod will only be created for the first timeActivityRun on . - In general
onCreateMethod will initialize the data of this page 、UIinitialization , Suppose the display data of the page is independent of the parameters passed by the page Jump , Don't worry about it - If the data displayed on the page is through
getInten()Method to get , Then problems will arise :getInten()It's always old data , There is no way to receive the new data transmitted during the jump !
- following , Explain it with an example :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-mloWwTV9-1637978600731)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26cff841e2?imageView2/0/w/1280/h/960/ignore-error/1)]
In the above code
CourseDetailActivityThe boot mode set in the configuration file isSingleTopPattern , According to the introduction of startup mode above , WhenCourseDetailActivityAt the top of the stack .Jump to page again
CourseDetailActivityIt will directly reuse the originalActivity, And the data to be displayed on this page is fromgetIntent()The way to do it , ButinitData()Method will not be called again , At this point, the page cannot display new data .Of course, this kind of situation system has been thought of for us for a long time , We need another callback
onNewIntent(Intent intent)Method . This method will pass in the latestintent, In this way, we can solve the above problems . The recommended way here is to go againsetIntent. And then again to initialize the data andUI. The code is as follows :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-vUjgTBf2-1637978600731)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26f4794839?imageView2/0/w/1280/h/960/ignore-error/1)]
- such , In a page can repeatedly jump and display different content .
2.4 Quick start one Activity
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-YRasJQIq-1637978600732)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26f46155c8?imageView2/0/w/1280/h/960/ignore-error/1)]
- In fact, this problem is relatively simple , Just don't
ActivityOfonCreateToo many heavy operations in method , And inonPasueMethod also can't do too much time-consuming operation .
2.5 Start process
Be careful ! This is not an answer
ActivityLife cycle of !
2.6 Activity Of Flags
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-WODqL5Bk-1637978600732)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26f431a604?imageView2/0/w/1280/h/960/ignore-error/1)]
Marker bit can be set Activity Start mode of , As mentioned above , Specify the startup mode dynamically , example
FLAG_ACTIVITY_NEW_TASKandFLAG_ACTIVITY_SINGLE_TOPetc. . It can also affectActivityOperating state , exampleFLAG_ACTIVITY_CLEAN_TOPandFLAG_ACTIVITY_EXCLUDE_FROM_RECENTSetc. .Here are a few basic marker bits , Don't memorize , Just understand a few , Check official documents when necessary .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-zTLqJ8V1-1637978600732)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab26f64ed138?imageView2/0/w/1280/h/960/ignore-error/1)]
FLAG_ACTIVITY_NEW_TASK
- The purpose is to
ActivityAppoint“SingleTask”Boot mode . With theAndroidMainfest.xmlThe specified effect is the same
FLAG_ACTIVITY_SINGLE_TOP
- The purpose is to
ActivityAppoint“SingleTop”Boot mode , With theAndroidMainfest.xmlThe specified effect is the same .
FLAG_ACTIVITY_CLEAN_TOP
- With this flag bit
Activity, At startup, theActivityOthers in the same task stackActivityOut of the stack . - Generally speaking, it is related to
SingleTaskStart mode appears together . - It will be over
SingleTaskThe role of . - But in fact
SingleTaskThe startup mode has the function of this flag bit by default
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
- With this flag bit
ActivityNot in the presentActivityList of - Use scenarios : In some cases, we don't want users to go back to
Activitywhen , This marker bit shows its effect . - It is equivalent to
xmlIt is specified inActivityProperties of .
2.7 onNewInstent() Method when to execute
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-o3JoQc5u-1637978600733)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2713491d3c?imageView2/0/w/1280/h/960/ignore-error/1)]
This is in startup mode , When this Activity There are already instances of , And the startup mode is SingleTask and SingleInstance , In addition, when this instance is at the top of the stack and the startup mode is SingleTop Can also be triggered when onNewInstent() .
3、 ... and 、 data
3.1 Activity Interpass Intent Transfer data size limit
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-1KYhCEzK-1637978600733)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2718c279eb?imageView2/0/w/1280/h/960/ignore-error/1)]
IntentThere is a size limit when passing data , Official didn't elaborate here , However, experimental methods can be used to measure the data should be limited to1MBwithin (1024KB)- We use delivery
BitmapMethods , Found when image size exceeds1024( To be exact1020about ) When , The program will flash back 、 Stop operation and other exceptions ( Different mobile phones react differently ) - So we can judge
IntentThe transmission capacity of1MBwithin .
3.2 When there is not enough memory, the system will kill the background Activity, If you need to save some temporary state , In which way
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-krAg2jOQ-1637978600734)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab271cea5c35?imageView2/0/w/1280/h/960/ignore-error/1)]
ActivityOfonSaveInstanceState()andonRestoreInstanceState()It's not a life cycle approach , They are different fromonCreate()、onPause()Equal life cycle approach , They don't have to be triggered .onSaveInstanceState()Method , When the application encounters an unexpected situation ( Such as : Out of memory 、 Users press directlyHomekey ) Destroy one by the systemActivity,onSaveInstanceState()Will be called .But when the user takes the initiative to destroy one
Activitywhen , For example, press the return key in the application ,onSaveInstanceState()It won't be called .Unless it's time to
activityIt was not destroyed by the user , UsuallyonSaveInstanceState()It's only suitable for keeping some temporary state , andonPause()Suitable for data persistence .
3.3 onSaveInstanceState() Executed scenarios
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-JtOVIZRs-1637978600734)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2734eb5c0d?imageView2/0/w/1280/h/960/ignore-error/1)]
- The system doesn't know you press
HOMEHow many other programs to run after , Naturally, I don't knowactivity AWill it be destroyed - So the system will call
onSaveInstanceState(), Give users the opportunity to save some non permanent data . The analysis of the following situations follows this principle :
- When the user presses
HOMEKey time - Long press
HOMEkey , When you choose to run another program - When the screen is locked
- from
activity AStart a newactivitywhen - Screen direction switching
3.4 Two Activity A method that must be executed when jumping between
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-ORzBiPHc-1637978600734)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2729e02a24?imageView2/0/w/1280/h/960/ignore-error/1)]
In general, for example, there are two activity , Respectively called A , B , When in A Activate inside B Component time , A Would call onPause() Method , then B call onCreate() , onStart() , onResume() .
This is the time B Form overridden , A Would call onStop() Method . If B It's transparent , perhaps Is the style of the dialog , Will not call A Of onStop() Method .
3.5 use Intent Go start a Activity Other methods
《Android Summary of learning notes + Latest mobile architecture video + Big Android interview questions + Project actual combat source code handout 》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 Full content open source sharing
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-dOh141zb-1637978600735)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2724c3da3d?imageView2/0/w/1280/h/960/ignore-error/1)]
- Use
adb shell amcommand
amStart aactivityadb shell am start com.example.fuchenxuan/.MainActivityamSend a broadcast , Useactionadb shell am broadcast -a magcomm.action.TOUCH_LETTER
3.6 scheme Jump agreement
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-ZRriHc1N-1637978600735)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab273d2660f7?imageView2/0/w/1280/h/960/ignore-error/1)]
3.6.1 Definition
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-1j53T9WG-1637978600736)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab273f2b0b6b?imageView2/0/w/1280/h/960/ignore-error/1)]
Server can customize jump
apppageappCan passSchemeJump to anotherapppageCan pass
h5Page JumpappNative PAGE
3.6.2 Form of agreement :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-L8tEOveN-1637978600736)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab27484aabff?imageView2/0/w/1280/h/960/ignore-error/1)]
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-P4R7eG46-1637978600737)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab275b9808fe?imageView2/0/w/1280/h/960/ignore-error/1)]
qhrepresentativeSchemeName of agreementtestrepresentativeSchemeAddress field of scope8080Represents the port number of the path change/goodsRepresents the specified page ( route )goodsIdandnameRepresents the two parameters passed
3.6.3 Scheme Use
- Define a
Scheme
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-vKtLKAwG-1637978600737)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2743ad29d1?imageView2/0/w/1280/h/960/ignore-error/1)]
- obtain
SchemeJump parameters
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-ev3aUWEj-1637978600738)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2765f5a51a?imageView2/0/w/1280/h/960/ignore-error/1)]
- Call mode
- Native call
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-DEQOQ2dO-1637978600738)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2766001c6d?imageView2/0/w/1280/h/960/ignore-error/1)]
- html call
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-tqO8XRI3-1637978600738)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab276d16ed37?imageView2/0/w/1280/h/960/ignore-error/1)]
- Judge a certain Scheme Whether it works
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-4Qf9Y8Cw-1637978600739)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab278265ad01?imageView2/0/w/1280/h/960/ignore-error/1)]
- About scheme Jump agreement , You can view the following blogs , Standing on the shoulders of giants , To see further Android Product development ( 11、 ... and )–> Jump in app Scheme agreement
Four 、Context
4.1 Context , Activity , Appliction The difference between
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Z9sbiCL8-1637978600739)(https://user-gold-cdn.xitu.io/2019/10/30/16e1ab2780c638c9?imageView2/0/w/1280/h/960/ignore-error/1)]
Jump parameters
[ Outside the chain picture transfer in …(img-ev3aUWEj-1637978600738)]
- Call mode
- Native call
[ Outside the chain picture transfer in …(img-DEQOQ2dO-1637978600738)]
- html call
[ Outside the chain picture transfer in …(img-tqO8XRI3-1637978600738)]
- Judge a certain Scheme Whether it works
[ Outside the chain picture transfer in …(img-4Qf9Y8Cw-1637978600739)]
- About scheme Jump agreement , You can view the following blogs , Standing on the shoulders of giants , To see further Android Product development ( 11、 ... and )–> Jump in app Scheme agreement
Four 、Context
4.1 Context , Activity , Appliction The difference between
[ Outside the chain picture transfer in …(img-Z9sbiCL8-1637978600739)]
边栏推荐
- 【面试经验包】面试被吊打经验总结(一)
- Expander+listbox of WPF effect
- Throttling and anti shake
- Learn PWN from CTF wiki - ret2text
- 社招面试必不可少——《1000 道互联网大厂 Android工程师面试题》
- 云原生架构(05)-应用架构演进
- 飞桨产业级开源模型库:加速企业AI任务开发与应用
- Android App bundle exploration, client development interview questions
- Return, const, volatile keywords
- All 32 keyword classifications of C language C89 (C90)
猜你喜欢

Revit API: schedule viewschedule

Complete open source project poetry bar app

【FreeRTOS】07 二值信号量、计数信号量

What is medical treatment? AI medical concept analysis AI

混沌工程,了解一下

kubernetes之常用核心资源对象

飞桨产业级开源模型库:加速企业AI任务开发与应用

paddle使用指南
![[image detection saliency map] calculation of fish eye saliency map based on MATLAB distortion prompt [including Matlab source code 1903]](/img/36/134c573c2198ca6c88a7c179189f1a.jpg)
[image detection saliency map] calculation of fish eye saliency map based on MATLAB distortion prompt [including Matlab source code 1903]

C language: structure array implementation to find the lowest student record
随机推荐
Fix blog theme php8 compatibility and optimize dark mode
C语言:结构体数组实现找出最低分学生记录
Drag and drop report design - new features of jimureport 1.4.0
【图像检测显著图】基于matlab失真提示鱼眼图显著图计算【含Matlab源码 1903期】
How to get started with machine learning?
Common WebGIS Map Libraries
利用Scanorama高效整合异质单细胞转录组
Nlp-d58-nlp competition d27 & question brushing D14 & Paper Reading & MathType
Google Earth Engine(GEE)——NDVI、NDWI和NDBI用来进行增加分类精度的验证结果(随机森林和cart分类)
What is the future development of palmprint recognition technology?
What do NLP engineers do? What is the work content?
[new cos series] | object storage cos data Vientiane CI processing special data processing resource package 4.5 folded into a big gift package!
[technical grass planting] Tencent Yunhao wool (consumption) record on the double 11
Comment utiliser l'entrepôt de données pour créer une table de synchronisation
Interview notes for Android outsourcing workers for 3 years. I still need to go to a large factory to learn and improve. As an Android programmer
测试 - 用例篇 - 细节狂魔
C语言:递归实现N的阶乘
钟珊珊:被爆锤后的工程师会起飞|OneFlow U
Complete collection of development environment configuration -- Visual Studio 2022 installation
Tiktok practice ~ one click registration and login process of mobile phone number and password (restrict mobile terminal login)