如何让service被管理器杀死后自动重启

做了个流量记录的程序,但是这个姑娘没有实现,也不知道怎么做,START_STICKY等FLAG不知道怎么用?
求帮助,谢谢大家,service主要代码如下
        @Override
        public IBinder onBind(Intent arg0) {
                // TODO Auto-generated method stub
                Log.v("TrafficService", "Bind");       
                state = BINLD;
                //使用线程,该线程不会被销毁
                return myBinder;
        }
       
       
        class TrafficBinder extends Binder { 
                public float his = history;
                TrafficService getService(){
                        return TrafficService.this;
                 }
        }
       
         @Override
         public void onCreate() {
                 // TODO Auto-generated method stub
                 receiver = new NetReceiver();
                 IntentFilter nfilter=new IntentFilter();       
                 nfilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
                 this.registerReceiver(receiver, nfilter);
                 dealBuffer();
                 handler.post(createBrod);
                 Log.v("TrafficService", "Create "+history+" "+todayTraffic+" "+tempTraffic);
                 super.onCreate();
                
         }
         @Override
         public boolean onUnbind(Intent intent) {
                 // TODO Auto-generated method stub
                 state = UNBINLD;
                 Log.v("TrafficService", "Unbind");
                 return true;
         }
        
         @Override
         public void onRebind(Intent intent) {
                 // TODO Auto-generated method stub
                 Log.v("TrafficService", "Rebind");
                 state = BINLD;;
                 super.onRebind(intent);
                
         }
        
         @Override
        public void onDestroy() {
                // TODO Auto-generated method stub
                 handler.removeCallbacks(updateBrod);
                 momorybuffer();
                 nManger.cancel(R.layout.notifi);
                 unregisterReceiver(receiver);
                
                 Log.v("TrafficService", "destroy "+history+" "+todayTraffic+" "+tempTraffic);
                 super.onDestroy();
        }
        
        @Override
        public boolean stopService(Intent name) {
                // TODO Auto-generated method stub
                momorybuffer();
                nManger.cancel(R.layout.notifi);
                Log.v("TrafficService",name.getAction());
                Log.v("TrafficService", "stop "+history+" "+todayTraffic+" "+tempTraffic);
                return super.stopService(name);
        }

       
       
        @Override
        public int onStartCommand(Intent intent, int flags, int startId) {
                // TODO Auto-generated method stub
                Log.v("TrafficService","startCommand");
               
                flags =  START_STICKY;
                return super.onStartCommand(intent, flags, startId);
//                return  START_REDELIVER_INTENT;
        }

你可能感兴趣的:(android)