网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Service中的Intentservice

1.类似于Activity类和其他组件,开发人员必须在应用程序配置文件中声明全部的service.为了声明Service,需要向标签中添加子标签如图 Mainest中的配置

公司主营业务:成都做网站、成都网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出绥德免费做网站回馈大家。

2.如  IntentService 工程 图一个service类在Activity 去startService

3.对于InternService 所包含的的的全部操作:没有参数的构造方法和onHandleIntent()方法,如果开发人员决定重写其他回调方法,如OnCreate()、OnStartCommand()或OnDestory(),需要调用父类实现,这样IntentService能正确处理工作线程的生命周期

4.Service类中的代码:

package com.example.intentservice;

import android.app.IntentService;
import android.content.Intent;
import android.text.format.Time;
import android.util.Log;

public class CurrentTimeService extends IntentService {

 

 public CurrentTimeService() {
  super("CurrentTimeService");
  // TODO Auto-generated constructor stub
 }

 @Override
 protected void onHandleIntent(Intent intent) {
  // TODO Auto-generated method stub
  Time time  = new Time();//创建对象
  time.setToNow();//获取当前系统时间
  String currentTime = time.format("%Y-%m-%d %H:%M:%S");
  Log.i("CurrentTimeService", currentTime);


 }

}

 

5.Activity类中的代码:

package com.example.intentservice;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class CurrentTimeActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  Button button1=(Button)findViewById(R.id.button1);
  button1.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    startService(new Intent(CurrentTimeActivity.this, CurrentTimeService.class));

   }
  });
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }

}

 

附件:http://down.51cto.com/data/2364289

网页标题:Service中的Intentservice
文章网址:http://bjjierui.cn/article/gdeios.html

其他资讯