ondestroy

Android: Activity.onDestroy() is not called when Dalvik kills this Activity

拟墨画扇 提交于 2019-12-08 16:10:00
问题 I'm confused about Activity.onDestroy() . I need to free some resources when my Activity is destroyed, but it seems like onDestroy() is called just when i press "Back" key, but not when my Activity is killed by Dalvik. I tested it just by adding log: Log.v("my_tag", "onDestroy() called"); and the same in onCreate() method too: Log.v("my_tag", "onCreate() called"); Then i start my Activity, and i see in logs: onCreate() called . I press "Back" key and then start Activity again, then i see:

Is onDestroy called only if you explicitly call finish() ?? or are there any exceptions?

只谈情不闲聊 提交于 2019-12-08 05:20:48
问题 I have a LocalBroadcastReceiver and I am unregistering it in my ondestroy() . Now i read about ondestroy() mentioned in these two SO answers is-ondestroy-not-always-called and why-implement-ondestroy-if-it-is-not-guaranteed-to-be-called and as well as in Androi Docs that onDestroy will be called if you explicitly call finish(); But why in my case I am not calling finish() but still ondestroy() is getting called everytime in all of my Android devices. Also according to you guys where are the

Will activity run onDestroy when system kill it?

房东的猫 提交于 2019-12-08 02:43:48
问题 I am wondering that will activity run the method "onDestroy" when killed by system? for example, when the state of "activity A" is onStop ( user may press the Home button directly ), at the same time, system find out that the memory is not enough so system have to kill some background processes to keep foreground activity alife, say system kill activity A. Will activity A run the method "onDestroy" in this situation? 回答1: It will purely depend on the system condition at that time. Docs

implications of AsyncTask.execute in onDestroy

眉间皱痕 提交于 2019-12-07 14:32:06
问题 I have this code running in my onDestroy function: @Override protected void onDestroy() { if (!(null == theUser.glideId)) { JSONObject req = new JSONObject(); try { req.put("actionKey", "UserPresenceInactive"); req.put("userId", theUser.userId); new ServerRequest().execute(req); //Run an AsyncTask } catch (JSONException e) { e.printStackTrace(); } } super.onDestroy(); } In the AsyncTask I send a request to a server (that comes back with just a 200 response). My question is, what are the

onDestroy() not getting called while the activity is getting killed by the user?

心已入冬 提交于 2019-12-06 16:55:52
I have an activity with two tabs. Clicking on two tabs will change the the fragments below the tabs. While that activity is in front I give out a notification, After that I minimize the app and kill that activity(not force stopping). My problem is that am not getting call back in onDestroy while the activity is been killed by the user. Now if I click the notification the app will force close and thats because the activity for pending intent is been missing. Why am not getting the call back in onDestroy? It is not sure to get callback in fragment's onDestroy() . When we kill the app Activity's

Dynamically registering a broadcast receiver [duplicate]

跟風遠走 提交于 2019-12-06 04:46:51
问题 This question already has an answer here : BroadcastReceiver as inner class (1 answer) Closed 2 years ago . I registered my broadcast receiver like this(given below) in the manifest file. its working fine. <receiver android:name="MyIntentReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> </receiver> But it stays registered through out. Ie whenever the phone is booting my

Why override Activity.onDestroy() if it isn't reliably called?

前提是你 提交于 2019-12-05 21:30:46
I'm confused why anyone would ever override Activity.onDestroy() instead of onPause() if according to the documentation : There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, I see much code that overrides onDestroy() despite this warning. Why? Why override Activity.onDestroy() if it isn't reliably called? It's not that it isn't reliably called... it's just that it isn't the only way the Activity can be killed. The Android system might trash your entire process without giving the ActivityManager the chance to

Handle app closing event from Launcher's menu

喜欢而已 提交于 2019-12-05 21:15:06
What I want to do is to know when user closes the app from Android Launcher's menu, which gets opened on home button long click: I want to do some operations when user closes the app. Actually, I want user to logout each time he leaves the app, but as long as he can close app in this was too, I have to handle this event and then make my operations. I've tried to google this one, but I couldn't find anything considering this. I don't want to override onStop() or onDestroy(), as long as the user may come back to the app then, in that case I don't have to make my changes. Don't advice this. I

Android onCreate Service called when Activity onDestroy called

≡放荡痞女 提交于 2019-12-05 17:26:40
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 BUT the solution suggested here of putting the service in another process doesn't work (at least on

How to call a method when an Android app is closed or loses focus?

我怕爱的太早我们不能终老 提交于 2019-12-05 02:22:57
问题 Because an app I'm building will handle rather sensitive data I want to sync the SQLite db with the server every time the user logs in, and remove emty the db every time the app loses focus (because the user moves to the home screen or another app). Seeing the Activity lifecycle, my idea was to do this by emptying the database in the onDestroy of every Activity. To test the described lifecycle I just Override all lifecycle methods (onCreate, onStart, onResume, onPause, onStop, and onDestroy),