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

定制建站费用3500元

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

成都品牌网站建设

品牌网站建设费用6000元

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

成都商城网站建设

商城网站建设费用8000元

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

成都微信网站建设

手机微信网站建站3000元

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

建站知识

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

android的Service的实例

package com.android.service;

import android.app.IntentService;
import android.content.Intent;

public class HelloIntentService extends IntentService{

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

    @Override
    protected void onHandleIntent(Intent intent) {
        // TODO Auto-generated method stub
        System.out.println("休息8秒");
        
        try{
            Thread.sleep(8000);
        }catch(InterruptedException e){
            e.printStackTrace();
        }
    }

    public void onDestory(){
        System.out.println("执行onHandleIntent之后会自动调用!");
        super.onDestroy();
        
    }
    
    
}

创新互联主要从事成都网站设计、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务永靖,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108

package com.android.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class HelloService extends Service{

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }
    
    public void onCreate(){
        super.onCreate();
        
        
        
    }

    public void onDestory(){
        
        super.onDestroy();
        
    }
    
    public void onStart(Intent intent,int startId) {
        // TODO Auto-generated method stub
        System.out.println("启动Service,休眠10秒");
        
        try{
            Thread.sleep(8000);
        }catch(InterruptedException e){
            e.printStackTrace();
        }
    }

    
    
}

package com.android.service;

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 MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button=(Button)findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent=new Intent(
                        MainActivity.this,HelloIntentService.class);
                startService(intent);
            }
        });
   

    Button button2=(Button)findViewById(R.id.button2);
    button.setOnClickListener(new OnClickListener() {
        
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent=new Intent(
                    MainActivity.this,HelloIntentService.class);
            stopService(intent);
        }
    });
    
    Button button3=(Button)findViewById(R.id.button3);
    button.setOnClickListener(new OnClickListener() {
        
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent=new Intent(
                    MainActivity.this,HelloService.class);
            startService(intent);
        }
    });
    
}
    

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

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    
   

其他资讯