Run only a background service when application start

后端 未结 1 1733
没有蜡笔的小新
没有蜡笔的小新 2021-01-15 04:41

I want to start only to start a service when my application start. Here is my code:

My Service class:

public class MyService extends Service {
 @Over         


        
1条回答
  •  悲哀的现实
    2021-01-15 04:53

    You going to need an main activity to call this service within onCreate if you want the service to start as soon as you start your application. In your main activity include this code in your onCreate.

    startService(new Intent(Main_Activity.this,MyServiceReceiver.class));

    This is just to call your service when you start up your application.

    0 讨论(0)
提交回复
热议问题