让程序(服务)开机运行

应用开发时有时候需要一些服务开机启动 ,在Android或者OPhone中实现开机启动很简单,只需实现一个Receiver即可。一个简单的Demo如下:
1.首先实现一个Reveiver:

 public class TestBootReceiver extends BroadcastReceiver {
         /* action to receive for an intent */
         private static final String TAG = "TestBootReceiver";


         @Override
         public void onReceive(Context context, Intent intent) {
                 String action = intent.getAction();
                 Log.i(TAG, " get ACTION:" + action);


                 if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
                         Log.i(TAG, "Start your service here...");
                       
                 }


         }
 }

2.把Receiver添加到Manifest当中:

 
         
                 
         

 

你可能感兴趣的:(action,android,ophone,string,service,class)