只有一个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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。