二手房网站建设方案,郑州一建,龙华网站制作要多少钱,网站建设思路方案说实话#xff0c;对于这个类在我实际工作中并没有用到过#xff0c;通常也只是用了它的父类Service#xff0c;通过官方文档可以看出类的层次结构: 而在今年的一次面试当中#xff0c;有个面试官提起了它#xff0c;所以虽说目前还没有真实在项目中用它#xff0c;但是有…说实话对于这个类在我实际工作中并没有用到过通常也只是用了它的父类Service通过官方文档可以看出类的层次结构: 而在今年的一次面试当中有个面试官提起了它所以虽说目前还没有真实在项目中用它但是有必要先了解一下它的用法在大脑中有一定的印象以便将来真正能用到时则直接参考既可。 对于这个类的使用当然不用自己摸索可以参考该博文:http://blog.csdn.net/hudashi/article/details/7986130 先依照官网的介绍有个大致的了解【来自银家博文】: 下面来把博文中说的例子给运行看下效果: 先声明服务MyIntentService: public class MyIntentService extends IntentService {final static String TAG cexo;public MyIntentService() {super(com.example.layouttest.MyIntentService);Log.i(TAG, this is constructed);}Overrideprotected void onHandleIntent(Intent arg0) {Log.i(TAG, begin onHandleIntent() in this);try {Thread.sleep(5 * 1000);} catch (InterruptedException e) {e.printStackTrace();}Log.i(TAG, end onHandleIntent() in this);}public void onDestroy() {super.onDestroy();Log.i(TAG, this is destroy);}
} 然后再主界面去调这个服务MainActivity: public class MainActivity extends Activity implements OnClickListener {// viewsprivate Button button;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button (Button) findViewById(R.id.button);button.setOnClickListener(this);}Overridepublic void onClick(View arg0) {Intent intent new Intent(this, MyIntentService.class);startService(intent);// 连续发起了三次请求startService(intent);startService(intent);}} 下面来看下运行的效果: 从运行效果可以发现跟Service的一个很大的区别在于同时发出多个请求之后当最后一个请求被处理则整个Service也退出了关于它真正的使用场景待在实际工作中用到了再来总结目前先学会怎么用它~ 总结: 在网上搜到了一个关于IntentService的一个特点我觉得有几点写出了它的好处: 转载于:https://www.cnblogs.com/webor2006/p/4305715.html