zoukankan      html  css  js  c++  java
  • 每日日报2021 4/23

    再来一段代码。

    public class TestService3 extends IntentService {  
        private final String TAG = "hehe";  
        //必须实现父类的构造方法  
        public TestService3()  
        {  
            super("TestService3");  
        }  
      
        //必须重写的核心方法  
        @Override  
        protected void onHandleIntent(Intent intent) {  
            //Intent是从Activity发过来的,携带识别参数,根据参数不同执行不同的任务  
            String action = intent.getExtras().getString("param");  
            if(action.equals("s1"))Log.i(TAG,"启动service1");  
            else if(action.equals("s2"))Log.i(TAG,"启动service2");  
            else if(action.equals("s3"))Log.i(TAG,"启动service3");  
              
            //让服务休眠2秒  
            try{  
                Thread.sleep(2000);  
            }catch(InterruptedException e){e.printStackTrace();}          
        }  
      
        //重写其他方法,用于查看方法的调用顺序  
        @Override  
        public IBinder onBind(Intent intent) {  
            Log.i(TAG,"onBind");  
            return super.onBind(intent);  
        }  
      
        @Override  
        public void onCreate() {  
            Log.i(TAG,"onCreate");  
            super.onCreate();  
        }  
      
        @Override  
        public int onStartCommand(Intent intent, int flags, int startId) {  
            Log.i(TAG,"onStartCommand");  
            return super.onStartCommand(intent, flags, startId);  
        }  
      
      
        @Override  
        public void setIntentRedelivery(boolean enabled) {  
            super.setIntentRedelivery(enabled);  
            Log.i(TAG,"setIntentRedelivery");  
        }  
          
        @Override  
        public void onDestroy() {  
            Log.i(TAG,"onDestroy");  
            super.onDestroy();  
        }  
          
    }
  • 相关阅读:
    适配器模式(16)
    状态模式(15)
    用反射技术替换工厂种的switch分支(14)
    2017年目标与规划
    抽象工厂模式(13)
    观察者模式(12)
    建造者模式(11)
    TCP 可靠传输与流量控制的实现
    TCP报文段的首部格式
    TCP可靠传输的工作原理
  • 原文地址:https://www.cnblogs.com/song-1/p/14853505.html
Copyright © 2011-2022 走看看