Questions tagged [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:

340 questions
5
votes
1 answer

Angular 2 ngOnDestroy is not triggering

Good morning fellows I've developed a small angular2-client-app which got routes. The routes are created like this: app.routes.ts import { provideRouter, RouterConfig } from '@angular/router'; import { ContactComponent } from…
Enis B
  • 140
  • 1
  • 7
5
votes
3 answers

How do I create a method similar to onDestroy in a simple non-activity java class?

I'd like to perform one or two actions when the instance of the class is shut down or destroyed. I'm looking for something similar to the onDestroy in an activity. EDIT I've added my code where I indicate how I serve back a SQLiteDatabase from my…
Jean
  • 137
  • 1
  • 13
5
votes
2 answers

$destroy event not working in angular

$scope.$on('$destroy', function (event){ $timeout.cancel(promiseObj); }); If i am on a page that is being loaded(since the page contain $http request, it takes time to load data) and while loading, I change the page from…
Omkar Telee
  • 77
  • 1
  • 7
5
votes
2 answers

Guaranteed alternative to onDestroy()?

I'm trying to execute some code whenever my activity is killed, but not when it's simply moved to the background (so just calling it in onPause() isn't a solution), and I understand onDestory() is not guaranteed to be called. I've been searching all…
Drazen Bjelovuk
  • 5,201
  • 5
  • 37
  • 64
5
votes
4 answers

How to automatically test onResume behaviour by calling onDestroy using Robotium?

I am using Robotium to functionally test an Android app. I'd like to test the onResume behaviour after onDestroy has been called. This post hints on using Instrumentation, but i can't get it to work. I have included the following, but this fails…
Bram
  • 101
  • 1
  • 6
4
votes
2 answers

Android onDestroy() method not working as expected

I use onDestroy() method, and my code is not completed: @Override public void onDestroy() { super.onDestroy(); for (int i = 0 ; i < 10; i++) { Toast.makeText(this, "Destroy " + i, Toast.LENGTH_SHORT).show(); …
Ziv Sion
  • 424
  • 4
  • 14
4
votes
1 answer

Dynamically registering a broadcast receiver

I registered my broadcast receiver like this(given below) in the manifest file. its working fine.
Prijin Koshy Alex
  • 1,837
  • 3
  • 14
  • 17
4
votes
2 answers

How to use OnDestroy properly

I've seen a lot of question related to ngOnDestroy. I think many of us not using it correctly or not using it at all. I just want to see a list of tips how can you properly use ngOnDestroy and what should we do in the best scenario to prevent memory…
4
votes
1 answer

How to distinguish whether onDestroy will be called after onPause

Is there any way how to distinguish whether onDestroy() will be called after onPause()? In may activity I need to do different action when Activity lost focus and when Activity is going down, but even when activity is going down onPause() is called…
esmeralda2
  • 169
  • 10
4
votes
1 answer

Android onCreate Service called when Activity onDestroy called

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…
MobileMon
  • 8,341
  • 5
  • 56
  • 75
4
votes
1 answer

Clicking Android notification creates a new activity instead of going to existing one

My app has a single running activity that creates a notification. When the notification is selected, instead of going to the running activity, the running activity is destroyed and a new activity is created - IN ANDROID 3.0 AND HIGHER. How do I…
D P
  • 41
  • 1
  • 4
4
votes
1 answer

view - looking for an event like on(View)Destroyed

Is there any way to listen to such an event? I have a custom EditText, which shows a FragmentDialog if it is clicked to pick a time, distance or a number, depending on the EditText setup... Now I'm using event bus based FragmentDialogs in my whole…
prom85
  • 16,896
  • 17
  • 122
  • 242
4
votes
4 answers

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

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).…
kramer65
  • 50,427
  • 120
  • 308
  • 488
4
votes
2 answers

How is my fragment's onCreateView called before it's onCreate when finishing the activity in onCreate?

This is very odd. I have a simple app which once logged in shows a fragment in an activity. The app also has an inactivity "timeout" after which time it finishes the activity and shows the login screen -- if the app is in the background when the…
4
votes
2 answers

android stop background service after activity crash

At the beginning, I would like apologize for bad english. There is my problem: I have a service in android which runs on background when is activity running. (This service synchronize user data with server with specified time intervals). public…