只有一个Service或Broadcast Reciver的android应用
package com.keenhi.tianpei;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class test_chargeReceive extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent intent1 = new Intent(context ,test_chargeService.class); context.startService(intent1);
} }
Service程序代码:
package com.keenhi.tianpei;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class test_chargeService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate()
{
System.out.println("service create");
}
}
Manifest.xml程序代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.keenhi.tianpei"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Test_chageActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="test_chargeService"></service>
<receiver android:name="test_chargeReceive">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
package com.keenhi.tianpei;
import android.app.Activity;
import android.os.Bundle;
public class Test_chageActivity extends Activity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="android.uid.system">
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:allowClearUserData="false" android:process="system"
android:killAfterRestore="false">
转自:http://blog.sina.com.cn/s/blog_76550fd701017qej.html
只有一个Service或Broadcast Reciver的android应用的更多相关文章
- Android 四大组件之service与Broadcast
Android 四大组件之一:service: Service有五个生命周期:onCreat,onStartCommand, onBind,onUnbind, onDestroy 主要有绑定和非绑定两 ...
- Android实训案例(七)——四大组件之中的一个Service初步了解,实现通话录音功能,抽调接口
Service Service的奇妙之处.在于他不须要界面,一切的操作都在后台操作,所以非常多全局性(手机助手,语音助手)之类的应用非常长须要这个.我们今天也来玩玩 我们新建一个project--Se ...
- Andriod ADB开启Activity、Service以及BroadCast(包括参数的传递)
/*****************开启Activity 并传递参数*******************/ 使用am命令启动Activity并传递参数的方法,也能用作C层与Java进行数据传递的一 ...
- springboot一个service内组件的加载顺序
先加载自身构造器,所以在构造器中初始化时若使用需要注入的(即@Autowired注解的)组件相关的方法,则会报null: 然后加载注入的组件即@Autowired 最后加载@PostConstruct ...
- 一个使用openGL渲染的炫丽Android动画库二(碎片化曲面动画)
续一个使用openGL渲染的炫丽Android动画库 MagicSurfaceView v1.1.0发布, 新增碎片化曲面动画 地址:https://github.com/gplibs/android ...
- 使用Angular CDK实现一个Service弹出Toast组件
在Angular中,官方团队在开发Material组件库的同时,顺手做了一套Component dev kit,也就是在Angular世界中大名鼎鼎的CDK,这套工具包提供了非常多的前端开发的通用功能 ...
- 如果一个service服务出现异常,无响应,如何定位,定位过程
假设一个service服务出现异常,要如何定位
- android音乐播放器(Service+ContentProvider+Broadcast+Activity四大组件完成)
1.获取音乐 1-1:获取手机中的音乐(用ContentProvider内容提供者来完成): package com.firefly.util; import java.util.ArrayList; ...
- Android怎么让一个service开机自动启动
1.首先开机启动后系统会发出一个Standard Broadcast Action,名字叫android.intent.action.BOOT_COMPLETED,这个Action只会发出一次. 2. ...
随机推荐
- sqlserver 索引
什么是索引 拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音. ...
- Codeforces Round #136 (Div. 2)
A. Little Elephant and Function 逆推. B. Little Elephant and Numbers \(O(\sqrt n)\)枚举约数. C. Little Ele ...
- POJ 1043 What's In A Name?(唯一的最大匹配方法)
What's In A Name? Time Limit: 1000MS Memor ...
- kuangbin_ShortPath S (POJ 3169)
被cow类题目弄得有些炸裂 想了好久好久写了120多行 依然长跪不起发现计算约束条件的时候还是好多麻烦的地方过不去 然后看了看kuangbin的blog 都是泪啊 差分约束的方式做起来只要70多行啊炒 ...
- BufferedInputStream/BufferedOutputStream复制文件
public class Test{ public static void main(String[] args) throws IOException{ FileInputStream in = n ...
- 此博客记录我的进阶之路(PHP、C、Python、Erlang)
强大自己!赚钱,装修,娶媳妇!!
- C#中IP地址转换为数值的方法
任何语言都通用的方法转换 IP 地址 a.b.c.d ==> a***+b**+c*+d ===> *(c+*(b+*a)) +d 示例: ***+**+*+ ===> *( +*( ...
- jquery ajax POST 例子详解
function test(){ $.ajax({ //提交数据的类型 POST GET type:"POST", //提交的网址 url:"testLogin.aspx ...
- RxJava + Retrofit 的实际应用场景
关于 RxJava Retrofit 很多篇文章都有详细的说明,在这里我想分享一个具体的使用案例,在我的开源项目 就看天气 里的实际应用.也希望跟大家探讨如何优雅的使用. 准备 项目中用到的依赖: c ...
- vb.net 动态调用api
Imports System Imports System.Runtime.InteropServices Public Class DllInvoke Public Sub New(ByVal DL ...