android-lifecycle

Android life cycle which event fired only once during the life cycle?

不羁岁月 提交于 2019-12-21 20:50:52
问题 I have read some blogs and visited some site. I want to know which event fired only one time during the life cycle. After reading blogs I realize that onCreate() method is fired only once during the life cycle. I don't know I am right or wrong. Now my problem is that I want to fired any event which fired one time only if I change the landscape orientation or portrait orientation than this event not fired means after starting activity if user change the orientation than event not fired. I want

Activity return to Portrait when Screen is Locked

两盒软妹~` 提交于 2019-12-21 19:53:02
问题 Related questions: https://stackoverflow.com/questions/15648713/strange-behaviour-while-screen-lock-in-landscape This is a strange behaviour i got in my Activities. Portrait mode (It's normal) Press screen lock, Activity: onPause() ; Unlock the screen, Activity: onResume() . Landscape mode (It's strange) Press screen lock, Activity: onPause() -> onStop() -> onDestroy() -> onCreate() -> onStart() -> onResume() which loads the Portrait layout; Unlock the screen, Activity: onPause() -> onStop()

is a view's “tag” restored when the activity whose layout contains the view is recreated?

依然范特西╮ 提交于 2019-12-21 08:17:08
问题 The docs concerning Activity recreation state: By default, the system uses the Bundle instance state to save information about each View object in your activity layout (such as the text value entered into an EditText object). So, if your activity instance is destroyed and recreated, the state of the layout is restored to its previous state with no code required by you. The docs for View.setTag(Object) state: Sets the tag associated with this view. A tag can be used to mark a view in its

Using system.exit(0) in onDestroy() (Android)

笑着哭i 提交于 2019-12-21 06:08:35
问题 I know that it is not recomended to use system.exit(0) in an Android application, but I was wondering if it would be ok to use it in onDestroy() since the application is allowed to be killed at that point? The reason I am asking is in relation to this question. 回答1: Do not rely that onDestroy will be called. There are situations where the OS will kill your application without calling your onDestroy . Just a word of advice, of course, as it does not directly apply to your scenario. If system

android: when to use onStart(), onStop()?

让人想犯罪 __ 提交于 2019-12-20 17:36:56
问题 I've read several posts that describe the difference between onStart() and onResume() : onStart() is called when the activity becomes visible, onResume() is called when the activity is ready for interaction from the user. fine. I've always just added code to onPause() and onResume() , and never bothered with onStart() and onStop() . Can anyone give some concrete examples of what you might do in onStart() , vs. onResume() ? Same goes for onStop() and onPause() , how is onStop() useful? I must

details of Android application components destruction and recreation

人走茶凉 提交于 2019-12-20 09:47:51
问题 Could someone push me in the direction of some concrete, trustworthy (and preferably concise) information on the following: The order in which components are destroyed and (where applicable)recreated by the system (Fragment, Activity, Activity's Threads/AsyncTasks/Timers, static data(when are classes unloaded?), Threads/AsyncTasks/Timers in other classes, host TabActivity, ActivityGroup, bound local Services, Application, process) both when the app is in the background, and in the foreground.

Fragment lifecycle with respect to it's activity

五迷三道 提交于 2019-12-20 09:29:47
问题 Situation My activity waits on an Async operation and after it hears back from async operation, it needs to pass information to 2 fragments inside it. Requirement 1. Both fragments need their onCreateView calls to be done for them to have their layouts loaded, 2. They need for themselves to be attached to their activity so that getActivity() works. I wrote a setData() method in both the fragments and am looking for the "correct" place in the activity's lifecycle to invoke them. onCreate() of

onStop delays to be called when restarting activity

烂漫一生 提交于 2019-12-20 07:39:53
问题 When restarting an Activity, onStop() from previous activity delays too much to be called. I am using this code to restart my activity PlayerActivity.java Intent playerIntent = getIntent(); playerIntent.putExtra(Constants.VIDEO_ID, videoId); playerIntent.putExtra(Constants.CATEGORY_ID, categoryId); playerIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); finish(); startActivity(playerIntent); Let's call PreviousPlayerActivity and NewPlayerActivity , the activity that was before and the new

onStop delays to be called when restarting activity

若如初见. 提交于 2019-12-20 07:39:10
问题 When restarting an Activity, onStop() from previous activity delays too much to be called. I am using this code to restart my activity PlayerActivity.java Intent playerIntent = getIntent(); playerIntent.putExtra(Constants.VIDEO_ID, videoId); playerIntent.putExtra(Constants.CATEGORY_ID, categoryId); playerIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); finish(); startActivity(playerIntent); Let's call PreviousPlayerActivity and NewPlayerActivity , the activity that was before and the new

android save programmatically created views

梦想与她 提交于 2019-12-20 03:46:15
问题 I programmatically create a RelativeLayout with some other views inside it and add it to the parent which is defined in XML. But all the views (incl. the layout) that were created programmatically disappear after the activity is re-created. Do I need a SharedPreferences object to save the values and then re-create the layout or is there an easier way to save it? P.S. all new created views get an id assigned 回答1: Do I need a SharedPreferences object to save the values and then re-create the