android开机启动service 适合闹钟程序
2010-09-15 00:07:00 来源:WEB开发网radar原创: 实例中一共三个类
public class yourReceiver extends BroadcastReceiver
public class ServiceTest extends Service
public class showActivity extends Activity
yourReceiver 类:
1. package radar.com;
2.
3. import android.content.BroadcastReceiver;
4. import android.content.Context;
5. import android.content.Intent;
6.
7. public class yourReceiver extends BroadcastReceiver {
8.
9. @Override
10. public void onReceive(Context context, Intent intent) {
11. Intent i = new Intent(context, ServiceTest.class);
12. i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
13. context.startService(i);
14. }
15.
16. }
复制代码
ServiceTest 类:
1. package radar.com;
2.
3. import java.util.Calendar;
4.
5. import android.app.Service;
6. import android.content.Intent;
7. import android.os.Handler;
8. import android.os.IBinder;
9. import android.util.Log;
10.
11. public class ServiceTest extends Service{
12. Handler hd1=new Handler();
13. /**启动activity的开关*/
14. boolean b;
15. /**启动一次activity之后的一分钟内将不再重新启动*/
16. int time;
17. public static final Intent ACTION_START = null;
18. private static final String TAG = "TestService";
19. @Override
20. public IBinder onBind(Intent intent) {
21. return null;
22. }
23. @Override
24. public boolean onUnbind(Intent i) {
25. Log.e(TAG, "============> TestService.onUnbind");
26. return false;
27. }
28.
29. @Override
30. public void onRebind(Intent i) {
更多精彩
赞助商链接