ondestroy

Detect ActionMode nesting

不羁的心 提交于 2019-12-23 02:53:07
问题 I use some custom ActionModes in my application. When an action mode is closed, I do some housekeeping, like closing related views, updating changes, etc.. I detect the action mode has been closed in OnDestroyActionMode. My problem is, when inside of some of my ActionModes, the user may trigger another system actionmode (The text copy/paste/select). In that case, onDestroyActionMode is called and I erroneously asume the user is done with the first actionmode, rather than implement a "stack"

Android onCreate Service called when Activity onDestroy called

五迷三道 提交于 2019-12-22 09:13:12
问题 I have an activity that starts a service. If I exit to home screen and then from the recent apps list manually close the activity, onCreate is called again in the service. So when the activity is destroyed, onCreate is called again (even though the service was running at the time onDestroy was called in the activity) I don't want onCreate in the service to be called again. I know its a possible duplication of this: Android service onCreate is called multiple times without calling onDestroy

How to distinguish whether onDestroy() is called as part of configuration change sequence?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 09:37:05
问题 In my Activity some external thing (service) need to be destroyed in onDestroy(). But I do not want this when configuration change happens (e.g. keyboard flips out) because it will be restored right away. So the question is: how to distinguish whether onDestroy() is caused by say Back-key press or part of config change process? after @CommonsWare's answer it would be pretty simple) something like: @Override onDestroy() { if (mIsChangeConfig == true) { mIsChangeConfig = false: } else {

Android: screen rotation, on destroy and services connundrum

会有一股神秘感。 提交于 2019-12-20 03:17:39
问题 I've modified the bluetooth chat example from the SDK demos to be able to control an arduino powered bluetooth LED matrix. Using the chat program, I can send messages to the display via bluetooth. I have a problem though. I've done two screen layouts, a portrait and a landscape. This way I can have the interface occupy the most space on the phone, regardless of orientation. The problem is that if the phone is rotated, OnDestroy() is called, to reload the new layout (landscape, or portrait).

Android: OnDestroy isn't called when I close the app from the recent apps button

有些话、适合烂在心里 提交于 2019-12-18 12:54:32
问题 When we press this button We see the apps which we didn't close, like this But when we want to close an app from this screen (below image), the method onDestroy() isn't called, however the app is closed. I need to call onDestroy() when the app is closed in this way. How can I do this? 回答1: As specified in the Android documentation, it is not guaranteed that onDestroy() will be called when exiting your application. "There are situations where the system will simply kill the activity's hosting

onDestroy() while “waiting” for onActivityResult()

烂漫一生 提交于 2019-12-18 02:18:31
问题 I have an app with two activities: "A" and "B". "A" uses startActivityForResult() to spawn "B" i.e. it waits for "B". Now, assume that "B" is in foreground. Can the Android system destroy activity "A" without also destroying "B"? (If yes, then when "B"is finished e.g. after user input, activity "A" must be recreated and put to the foreground again by the Android system, and I need to remember and restore "A" to its earlier UI status.) Note that I'm not talking about process kill (which is

What exactly does onDestroy() destroy?

感情迁移 提交于 2019-12-17 22:57:25
问题 I've been bothered by this "characteristics": When I use Back button to leave my app, I can tell onDestroy() is called, but the next time I run my app, all the static members of the Activity class still retain their values. See the code below: public class HelloAndroid extends Activity { private static int mValue; // a static member here public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText((mValue != 0) ? ("Left

Activity's onDestroy / Fragment's onDestroyView set Null practices

∥☆過路亽.° 提交于 2019-12-17 17:29:52
问题 I am reading ListFragment source code and I see this implementation: ListAdapter mAdapter; ListView mList; View mEmptyView; TextView mStandardEmptyView; View mProgressContainer; View mListContainer; CharSequence mEmptyText; boolean mListShown; /** * Detach from list view. */ @Override public void onDestroyView() { mHandler.removeCallbacks(mRequestFocus); mList = null; mListShown = false; mEmptyView = mProgressContainer = mListContainer = null; mStandardEmptyView = null; super.onDestroyView();

Android save state on orientation change

感情迁移 提交于 2019-12-17 17:29:12
问题 I've got an Android application which maintains state regarding distance traveled, time elapsed, etc. This state I can conveniently store in an object and store a reference to that object in the Bundle when Android calls onDestroy() when the user changes the screen orientation, then restore the state in onCreate(Bundle savedBundle). However, I also have some state in the Buttons and EditText objects on the screen that I want to persist through screen orientations. For example, in onStart

Is ondestroy not always called?

做~自己de王妃 提交于 2019-12-17 04:35:11
问题 I have put some cache cleaning code in onDestroy of my activity but most of the time the code is not executed unless I explicitly finish the activity via finish() . Edit: Just read onDestroy is called only with finish() or if the system is low on resources. So where do I need to put my cache cleaning code? If I put it in onPause() and the user goes back to the app, the cache is cleared. I am actually storing important temporary files in the cache that should not be deleted in onPause . 回答1: