Android启动服务不启动应用程序? [英] Android start service without starting application?

查看:32
本文介绍了Android启动服务不启动应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不启动应用程序的情况下启动服务?我需要至少每小时刷新一次我的应用程序的数据,如果我的应用程序中没有用户,我该怎么做?

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?

推荐答案

您可以在启动时启动您的服务.您的 AndroidManifest.xml 文件中需要以下内容:

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

  1. 在你的中元素:

  1. In your <manifest> element:

在您的<应用程序>中元素(确保为您的 BroadcastReceiver 使用完全限定的 [或相关] 类名):

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

在 MyBroadcastReceiver.java 中:

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);
    }
}

这篇关于Android启动服务不启动应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆