Questions tagged [android-ondestroy]

Tag for questions related to Android's onDestroy() method of Activities and Services.

The onDestroy() method is one of the lifecycle methods for Activities and Services on the Android platform. This method is the last method to be called before an Activity or a Service is killed. More information about this method can be found at the links below:

60 questions
14
votes
3 answers

Prevent activity from being destroyed

I'm sending an intent to the camera from an activity that I call like this: Intent testphoto = new Intent(Dashboard.this,CameraHandler.class); startActivity(testphoto); In the CameraHandler class I call the camera: Intent intent = new…
Diego
  • 4,011
  • 10
  • 50
  • 76
10
votes
5 answers

Remove notification when service destroyed by android OS

I created an app which shows Notification when Service.onStartCommand() method executed and hide notification when Service.onDestroy() is called. Its works fine for normal calls to startService() and stopService(). Service Code: @Override public…
user1041858
  • 947
  • 2
  • 15
  • 32
7
votes
0 answers

android Fragment re-creation after onDestroy - FragmentManagerState ClassNotFound

I'm working on an activity with a viewpager with 3 fragments. After starting a pick image intent onactivityResult is called but the starter activity is destroyed & created again. (I've turned on Don't keep any activities,Developer settings.) Now…
6
votes
3 answers

Can Android kill the activity without killing the entire process while the app is in the background?

I'm wondering if Android system is able to kill the activity without the entire application process while the app is minimized. From Android documentation we know that onDestroy is only called when the activity is about to be destroyed and the…
4
votes
1 answer

Notification still appear when app is closed

i'm trying to close notification when my app being closed,because when i close the app from (Recent Task / Swipe to exit),notification still appear and in case user try to click on notification the app will crash. @Override protected void…
ali
  • 189
  • 3
  • 14
3
votes
2 answers

SharedPreferences not saved in onDestroy of Service

Before the activity get's killed (when OnDestroy is called), I am saving some int values in SharedPreferences. But what I have noticed is that it takes about a second for the values to be saved but the app doesn't wait for that before destroying…
2
votes
1 answer

[Android]Error:"Can not perform this action after onSaveInstanceState" without using it

I'm a beginner with android and i have to create a simple app that handle a lessons book for students. Basically, sometimes i log out and crash with this error, sometimes not. I don't use se function "onSaveInstanceState" but give me error when i…
2
votes
1 answer

How to trigger an event, when app is removed from Recent List in Android

I want to restart my app when it is removed from recent list. I have added the restarting code in onDestroy() method. It's working fine in Android 7 and up. But on Android 6 and older versions, it's not working. onDestroy() method is called only…
2
votes
1 answer

Removing Preference data when Application killed

In my application i am storing some SharedPreference data. I have to clear that all stored data when application killed. So, I have done it in my activity's onDestroy() as below : @Override protected void onDestroy() { if(isBackPressed==0){ …
Jaimin Modi
  • 1,530
  • 4
  • 20
  • 72
2
votes
2 answers

Clear cache on webview when the app is killed

I have seen other answers on stackoverflow but none of them helped me solve my issue. I have an application with webview in a activity, I want to clear cache when the application is killed. Below is the code I'm using to delete the cache- public…
2
votes
0 answers

Widget not working after Force quit App

I have a widget that works well in all cases except when the app is forced quit. When that happens, any touch or button press on the widget is not working. However, when the app is launched again, the widget works again. Even if I kill the app (by…
Ziad Halabi
  • 964
  • 11
  • 31
1
vote
1 answer

Fragment leaking in ViewPager2 with FragmentStateAdapter on onDestroyView()

FYI: The question is short, but just in case I added more information at the end that may be relevant. I needed an infinite scrolling ViewPager2, and I wanted to reuse a Fragment from the project as it was already designed and calls already well…
1
vote
1 answer

onCreate and onDestroy called after navigating away fragment

I noticed that in my Android app, after navigating away from a fragment, the onCreate() and onDestroy() methods are still called. This causes my code to throw an exception as the onDestroy() method refers to resources(specifically, my ViewModel)…
LCZ
  • 589
  • 1
  • 9
  • 15
1
vote
1 answer

How to send result Intent using onPause (back button)

I have an Activity that contains a Recycler view and is called from the main activity with an extra string. The user would then do some things that would change the string and I would like to send it back to the Main activity. Is there a way to do…
1
vote
1 answer

Android - onDestroy() called after onCreate()

I have a screensaver activity running, a small animation. When the user touches the screen, they are moved to my MainActivity. To do so, I am overriding the method "onUserInteraction()". In case you're not familiar, any physical touch to the…
1
2 3 4