Android实现开机加载service
来源:互联网 发布:mac下载flash好慢 编辑:程序博客网 时间:2024/05/20 00:13
很多程序都需要在Android开机的时候启动服务,相对的J2ME的麻烦,Android给了我们一个很方便的实现方法。
现在我以我开发的密信软件的开机软件服务COS一下如何实现这个目的。
首先必须有一个BroadcastReceiver以便监听手机开机intent, 而该receiver又负责启动你的service或者activity.
package com.lusgarden.texts.utils;
import com.lusgarden.texts.systems.MainService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootStrService extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
Intent i = new Intent(MainService.ACTION_START);
//其中MainService为我要加载的service
//.ACTION_START为一个常量,需在MainService定义,值为"android.intent.action.BOOT_COMPLETED"
i.setClass(context, MainService.class);context.startService(i);
}
}
其次,就需要在Manifest文件中声明一下intent-filter: 先加入使用权限声明:
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
然后加入receiver 注册声明:
- <receiver android:name=".BootStrService" >
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- </receiver>
- 其实整体来说,安卓还是比较容易开发的移动应用。
- 这样开机后.BootStrService 就能收到开机的intent,然后自动启动我所需要启动的MainService.
- Android实现开机加载service
- Android实现开机自启动Service
- Android实现开机自启动Service
- Android实现开机自启动Service
- Android 实现开机自启动 Service
- Android实现开机自启动Service
- Android实现开机自启动Service
- Android实现开机自启动Service
- Android如何实现开机自启动Service
- Android如何实现开机自动启动Service
- Android开机启动Service
- Android开机启动Service
- Android开机启动Service
- 【Android】开机启动 Service
- android开机启动Service
- Android 开机启动Service
- android 使用BroadcastReceiver实现开机启动Service或Activity
- android如何实现开机自动启动Service或app
- -重要的SharedPreferes
- 12月19日工作总结
- ASP.NET 图片防盗链的实现原理分析
- quick sort 快速排序
- 孙惟微:《赌客信条:你不可不知的行为经济学》
- Android实现开机加载service
- Windows下手动生成dump文件
- 【Linux入门学习之】vi/vim编辑器必知必会
- 教你怎样恢复关机前打开的窗口
- 恶心的社会
- Android实现短信应用手动添加入数据库
- 2011百校联动“菜鸟杯”程序设计公开赛(现更新5道)
- div css background背景
- NoSQL