I came across two different types to start my activity based on some parameters. The first is savedInstanceState , and the other getIntent.getExtras ()
Q1) Therefore, I do not understand, as soon as I pass the bundle to my activity and then run it, it should have a package. But, if for some reason the activity is recreated again, it must have the same set again and again. (I'm right?)
Q2) Based on the fact that Q1 is true, and the fact that I canโt just redefine the package after the activity has already started, I assume that if for some reason the Activity is already running, I want to change some params beam, I have to create activity fields and use these fields in my life. And override saveInstanseState to save the new fields if for some reason my activity is recreated. it's true?
Q3). Based on the fact that all of the above is true, in onCreate () so that every activity in the Android world should start as follows:
if (savedInstanceState != null) { mType = savedInstanceState.getInt("some_val1"); mCardId = savedInstanceState.getLong("some_val2"); mQuery = savedInstanceState.getString("some_val3"); mCategory = savedInstanceState.getLong("some_val4");; } else { mType = getIntent().getExtras().getInt("some_val1"); mCardId = getIntent().getExtras().getLong("some_val2"); mQuery = getIntent().getExtras().getString("some_val3"); mCategory = getIntent().getExtras().getString("some_val4"); }
Q4) Suppose that onSaveInstanceState is called and stores values โโdifferent from the original package that started the activity (getIntent.getExtras). If the activity is recreated again, does this mean that saveInstanceState is different from getIntent.getExtras (), or are they the same now? (If they match, then if / else in the code above does not have a true value, because it is one and the same!).
Q5) If I did not redefine onSaveInstanceState , but when I created the action, I passed the Bundle to it, it still means that I can get my original package if the activity is recreated again? (I think this question will be answered by myself, based on other answers)
android android-activity android-lifecycle
winter
source share