Android start service without starting application?

后端 未结 2 1431
陌清茗
陌清茗 2020-12-20 07:54

Is it possible to start service without starting application? I need to refresh data of my application at-least hourly, how can I do it if user no in my application?

2条回答
  •  时光取名叫无心
    2020-12-20 08:22

    you can start your service on boot. You need the following in your AndroidManifest.xml file:

    1. In your element:

    2. In your element (be sure to use a fully-qualified [or relative] class name for your BroadcastReceiver):

    In MyBroadcastReceiver.java:

    package com.example;
    
    public class MyBroadcastreceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            Intent startServiceIntent = new Intent(context, MyService.class);
            context.startService(startServiceIntent);
        }
    }
    

提交回复
热议问题