ondestroy

Android save state on orientation change

笑着哭i 提交于 2019-11-28 16:13:56
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(Bundle savedBundle) I call: _timerButton.setBackgroundColor(Color.GREEN); _pauseButton.setBackgroundColor

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

泪湿孤枕 提交于 2019-11-28 03:49:46
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(); } In this function, Google developers set Null to all view fields that declared in ListFragment and

Activity is getting destroyed while pressing the home button

孤街浪徒 提交于 2019-11-28 03:18:48
问题 In my application, when I press the home button the activity is going to onDestroy() . It suppose to be called onPause() method only right? Why it is happening so? 回答1: It depends on how much memory your phone has, if your phone does not have very much memory, then it will destroy the activity to free up resources immediately. On new phones, this will not happen because they have plenty of spare memory. 回答2: also check that you don't use the android:noHistory flag in your manifest for the

How to restart a killed service automatically?

放肆的年华 提交于 2019-11-28 00:55:45
问题 When a service has been killed, how to restart it automatically? sometimes without even calling onDestroy() 回答1: I inherited an IntentService, so I had to be gentle. It worked for me when I overrode onStartCommand() but public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); return START_STICKY; } That is, let the parent do what it should and return START_STICKY. 回答2: Overrides the onStartCommand() and give START_STICKY or START

Android app doesn't call “onDestroy()” when killed (ICS)

我只是一个虾纸丫 提交于 2019-11-27 22:00:34
I'm developing an android app using bluetooth communication (using a propetary protocol) and I need to catch the moment when the app is killed. I wanted to use the "onDestroy()" method but it isn't called every time the app is killed. I noticed that it is called when I press the back button and, only sometimes, when I kill the app from the task manager. The question is: How can I catch the moment before the app is killed? Here is the code I tried to use: @Override public void onDestroy() { sendMessage(msg); Log.d("SampleApp", "destroy"); super.onDestroy(); } @Override public void finish(){

Android: Will finish() ALWAYS call onDestroy()? [duplicate]

怎甘沉沦 提交于 2019-11-27 14:37:22
This question already has an answer here: what exactly Activity.finish() method is doing? 12 answers Simple question: can you be sure that finish() will call onDestroy() ? I haven't found any confirmation on this. Simple question: can you be sure that finish() will call onDestroy()? First, this answer assumes that you are referring to Android's Activity class and its finish() method and onDestroy() lifecycle method. Second, it depends upon your definition of "sure": Your process could be terminated in between finish() and onDestroy() , for reasons independent of whatever is triggering the call

How to make notification resume and not recreate activity?

时光怂恿深爱的人放手 提交于 2019-11-27 14:29:20
问题 I thought I had this figured out, but after some debugging on this question: How to make notification uncancellable/unremovable I just realized my activity is still getting onCreated() and onDestroyed(), in random order. My manifest for the activity: <activity android:name="***.***.***.*****" android:configChanges="orientation|keyboardHidden" android:label="@string/app_name" android:screenOrientation="portrait" android:launchMode="singleTop" > <intent-filter> <action android:name="android

Android service onCreate is called multiple times without calling onDestroy

ぐ巨炮叔叔 提交于 2019-11-27 13:18:38
In my app, I use a service to communicate with our server. The Service spawns several message queue threads to deal with tasks with different priorities. This model has been used for about one year without big issues. However, recently, I found some time the onCreate of my service class are called multiple times. onDestroy is never called between two onCreate calls. Therefore, I did not get chance to kill existing threads. Once this behavior happens, the service has duplicate threads inside. The only thing I have changed is to run the service as foreground service is a user signs in the app. I

onDestroy gets called each time the screen goes on

北城余情 提交于 2019-11-27 08:16:54
My application gets killed each time that it comes back from the screen-off-state. I fetch all the information that my app does, but I can't find out why it calls onDestroy. It's the first time I'm seeing this behavior in my applications. My main activity extends tabActivity because it contains a tabhost. I've read that it has to extend it or it will FC. I'm not sure if my issue is related to this?! Oh and it implements Observer but this should be no problem. Here are the logs: 07-21 09:57:53.247: VERBOSE/###(13180): onResume 07-21 09:57:53.267: VERBOSE/###(13180): onPause 07-21 09:57:59.967:

Situations when a Service's onDestroy() method doesn't get called?

安稳与你 提交于 2019-11-27 06:13:11
问题 I'm aware that a Service's onDestroy() method may never be called but can someone tell me when such a scenario might occur? I'm especially interested in whether it's possible for a Service to be killed, yet its VM would continue to run. I ask because I have a service that registers ContentObservers in the service's onStartCommand() method and unregisters them onDestroy(). If the service's onDestroy() method was never called because the whole VM was killed (along with the observers it created,