android-lifecycle

Why use Fragment#setRetainInstance(boolean)?

﹥>﹥吖頭↗ 提交于 2019-11-26 10:22:39
I find Fragment#setRetainInstance(true) confusing. Here is the Javadoc, extracted from the Android Developer API : public void setRetainInstance (boolean retain) Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change). This can only be used with fragments not in the back stack. If set, the fragment lifecycle will be slightly different when an activity is recreated: onDestroy() will not be called (but onDetach() still will be, because the fragment is being detached from its current activity). onCreate(Bundle) will not be called since the

What is the correct order of calling superclass methods in onPause, onStop and onDestroy methods? and Why?

半世苍凉 提交于 2019-11-26 10:08:25
问题 I was just going through the Android Developer Site, refreshing on the Activity Life cycle, and in each code example, there is a comment beside the super class methods that says \"Always call the superclass method first\". Though this makes sense in the creation half cycle: onCreate, onStart and onResume, I\'m a little confused as to what is the correct procedure on the destruction half cycle : onPause,onStop,onDestroy. Destroying the instance specific resources first, before destroying

What is the benefit of using Fragments in Android, rather than Views?

落爺英雄遲暮 提交于 2019-11-26 08:45:17
问题 When developing for Android , you can set your target (or minimum) sdk to 4 (API 1.6) and add the android compatibility package (v4) to add support for Fragments . Yesterday I did this and successfully implemented Fragments to visualize data from a custom class. My question is this: what is the benefit for using Fragments as opposed to simply getting a View from a custom object, and still supporting API 1.5? For example, say I have the class Foo.java: public class Foo extends Fragment { /**

One Activity and all other Fragments [closed]

徘徊边缘 提交于 2019-11-26 06:55:20
问题 I am thinking of implementing one screen with Activity and all other sreens with Fragments and managing all the fragments thru the activity . Is it a good idea? and my answer is NO but still I want to know more clearly about this thought. What are the pros and cons of the idea? Note: Please don\'t give me the link for fragment and activity. EDIT: Here is something over Fragments and activity: Pros: Fragments are meant to be used with activities as a sub activity. Fragments are not the

Android: Under what circumstances would a Dialog appearing cause onPause() to be called?

痴心易碎 提交于 2019-11-26 04:08:47
问题 A snippet from the Android Activities document(scroll down to the \" foreground lifetime \" line) says : An activity can frequently transition in and out of the foreground—for example, onPause() is called when the device goes to sleep or when a dialog appears . I don\'t quite understand this. Under what circumstances should this happen? Is onPause() called only if the context of the dialog in question is different from the activity on top of which the dialog is to be displayed? EDIT: Adding

App restarts rather than resumes

廉价感情. 提交于 2019-11-26 04:02:57
问题 Hopefully someone can help me figure out, if not a solution, at least an explanation for a behaviour. The Problem: On some devices, pressing the launcher icon results in the current task being resumed, on others it results in the initial launch intent being fired (effectively restarting the app). Why does this happen? The Detail: When you press the \"Launcher Icon\" the app starts normally - That is, I assume, an Intent is launched with the name of your first Activity with the action android

How to know when my app has been killed?

☆樱花仙子☆ 提交于 2019-11-26 02:50:23
问题 I need to know when the user kills my app (Force stop). I\'ve been reading the android lifecycle, which has the onStop() and onDestroy() functions, these are related to each activity the user ends on my app, but not when the user forces stop or kills my app. Is there any way to know when the user kills the app? 回答1: there's no way to determine when a process is killed. From How to detect if android app is force stopped or uninstalled? When a user or the system force stops your application,

Why use Fragment#setRetainInstance(boolean)?

淺唱寂寞╮ 提交于 2019-11-26 02:07:27
问题 I find Fragment#setRetainInstance(true) confusing. Here is the Javadoc, extracted from the Android Developer API: public void setRetainInstance (boolean retain) Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change). This can only be used with fragments not in the back stack. If set, the fragment lifecycle will be slightly different when an activity is recreated: onDestroy() will not be called (but onDetach() still will be, because

Android static object lifecycle

孤者浪人 提交于 2019-11-26 01:41:34
问题 I am creating event search application, we set search criteria from one screen populate in another screen then user can edit search criteria from 3rd screen and goes to 4th screen. To achieve above task i am using static object which remember the values around the application and i don\'t need to do any thing extra. But i am afraid if about static object life cycle in android if low memory found android delete static objects ??? As android supports multi tasking, if user switches to another

On logout, clear Activity history stack, preventing “back” button from opening logged-in-only Activities

雨燕双飞 提交于 2019-11-26 01:36:42
问题 All activities in my application require a user to be logged-in to view. Users can log out from almost any activity. This is a requirement of the application. At any point if the user logs-out, I want to send the user to the Login Activity . At this point I want this activity to be at the bottom of the history stack so that pressing the \"back\" button returns the user to Android\'s home screen. I\'ve seen this question asked a few different places, all answered with similar answers (that I