Android – ondestroy() of the calling service

I want to make a phone call

Service methods in Android

I have searched a lot on the Internet, and many answers are like

Service troops stop or in some way their ondestroy () will never call

But I really need to know when to stop service

My project is about music players

So it uses the service and keeps informing. I need to find out when the service stops? And need to stop music and delete notifications

But it never shows any logs of ondestroy (). Anyone can help me. What is its substitute? If it's not ondestroy (), which method?

Edit:

I don't want to explicitly call ondestroy. I want to delete the notification when I delete my application from the device menu running the application. Because ondestroy won't call when I stop my application, and my notification remains in the status bar

I have started my service with this code. Intent play = new intent (this, musicservice. Class); Startservice;

resolvent:

In the Service class, call:

stopSelf();

From another class, such as your mainactivity:

Intent i = new Intent(this,ServiceName.class); stopService(ⅰ);

Both will stop your service. Make sure you return to start_ NOT_ Sticky so that the service will not start again

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>