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
0
votes
1 answer

Error during creating dialog inside onDestroy : Can not perform this action after onSaveInstanceState Android

I have transparent activity after I kill it (onStop/onDestroy) i want to create Dialog but I getting error : java.lang.RuntimeException: Unable to destroy activity {package name/myclass}: java.lang.IllegalStateException: Can not perform this action…
user3753721
0
votes
1 answer

Android OS killing service, notification is staying

My Android App plays audio. The app starts a service, the service starts a notification with media buttons. When the OS is low on resources, the OS kills my service. Yet the notification, with the media buttons, is staying. Because the service is…
0
votes
1 answer

How to know if a user triggered onDestroy in an Activity and not the system?

I am writing a service which stays open in background and records user action. Now, if a user finish the App Activity by pressing the back key or swiping the app away in the recent apps screen I want to finish the background service as well, but if…
0
votes
0 answers

Android onDestroy being called when it shouldn't

I have three Activities (A, B and C). Activity A is used to sign in. After a successful sign in Activity A is starts Activity B and then Activity A is killed (using finish()). Activity B has a button to start Activity C (Activity B has not been…
0
votes
0 answers

Delete notification in OnDestroy event

I need to cancel the notification of my application when my application terminates (when it is removed from the taskmanager). To clear the notification I wrote this method. public void deleteNotification(){ NotificationManager notifManager =…
0
votes
1 answer

Android - what happens when the app is forcibly killed

Through Android's Activities doc, it is said that the methods onStop() and onDestroy() are not guaranteed to be called. [...] once the activity is created, onPause() is the last method that's guaranteed to be called before the process can be…
0
votes
2 answers

Run long task when onDestroy() is called

I want to run a long operation task from onDestroy() from a fragment. My goal is to call a network call to delete some data in case the user closes the application by swiping it from recent apps. I wish to start an intent when onDestroy() is…
Dus
  • 4,052
  • 5
  • 30
  • 49
0
votes
1 answer

android calling recreate in onDestroy()

Can I call recreate() in onDestroy() method of MainActivity? The idea is to restart the activity whenever OS stops it. Is it possible and are there any disadvantages of doing this. Basically, I have a blank activity that starts many services, but…
And_Dev
  • 113
  • 2
  • 12
-1
votes
1 answer

How to kill previous service before start new service in Java?

I am coding an Android app using Android Studio. My service class takes the values from the main activity class when starting the service. However, when I reassign the values in the main activity, the change is not applied to the value in the…
-1
votes
2 answers

What is wrong with onDestroyView() method?

I am trying to save values in my pref before fragment is destroyed but an error message says android.support.v4.app.SuperNotCalledException: Fragment did not call through to super.onDestroyView() here is my code @Override public void…
-1
votes
2 answers

onDestroy method is not calling in android o version

I want to call method in ondestroy override method but that override method is not calling android o only. Why it is not calling is there any alternative for that please any one help me to resolve my issue.Thanks in advance.
v teja
  • 613
  • 2
  • 7
  • 17
-1
votes
1 answer

Get Intent passed to stopService(intent) in Service

I have a requirement to detect source of destroying service. I am using intent and extra while calling stopService(intent). But where to catch this intent in Service class to act upon. Already gone through android docs, nothing helpful found. Any…
SimpleCoder
  • 1,665
  • 1
  • 21
  • 34
-2
votes
4 answers

What can we do to ensure that onDestroy() gets called?

I have a line of code that I should call after my activity is destroyed, so I override onDestroy() method and I call it inside. Like this: @override public void onDestroy(){ //my code here super.onDestroy() } Now I noticed…
Hasan Bou Taam
  • 4,017
  • 2
  • 12
  • 22
-2
votes
1 answer

Objects in Fragment get destroyed when Fragment is destroyed?

Are objects in Fragment get destroyed when Fragment it is in gets destroyed? I.e. when onDestroy() is called.
kent218
  • 41
  • 1
  • 4
-2
votes
3 answers

I cannot stop Location service from my fragment. How can stop it?

I start my service from onCreateView like getActivity().startService(new Intent(getActivity(), LocationService.class)); And I try to stop my service like this @Override public void onDestroyView() { getActivity().stopService(new…
Harsh Patel
  • 657
  • 11
  • 26
1 2 3
4