日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
詳細(xì)描述Android服務(wù)解說

開放手機(jī)聯(lián)盟的成立和 Android服務(wù) 的推出是對現(xiàn)狀的重大改變,在帶來初步效益之前,還需要不小的耐心和高昂的投入,谷歌將繼續(xù)努力,讓這些服務(wù)變得更好,同時也將添加更有吸引力的特性、應(yīng)用和服務(wù)。

成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)雙鴨山,十載網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108

一,Android服務(wù)中的Service與調(diào)用者在同一線程,所以要是耗時的操作要在Service中新開線程。
二,Android的Service中,主要是實現(xiàn)其onCreate,onStart, onDestroy,onBind,onUnBind幾個函數(shù),來實現(xiàn)我們所需要的功能。

簡單的調(diào)可以在調(diào)用者對象中使用Context.startService來調(diào)用,以Intent為參數(shù),當(dāng)然,Intent搜索,匹配目標(biāo)的方式與以前在《Intent使用》中方式一樣。

下面來看一段例程:

 
 
 
  1. package test.pHello;
  2. import android.app.Activity;
  3. import android.content.ComponentName;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.ServiceConnection;
  7. import android.net.Uri;
  8. import android.os.Bundle;
  9. import android.os.IBinder;
  10. import android.view.Menu;
  11. import android.view.MenuItem;
  12. import android.widget.TextView;
  13. public class HelloActivity extends Activity { 
  14.  
  15.  ITestService mService = null;
  16.  ServiceConnection sconnection = new ServiceConnection()
  17.  {
  18.   public void onServiceConnected(ComponentName name, IBinder service)
  19.   {
  20.    mService  = (ITestService)service;
  21.    if (mService != null)
  22.    {
  23.     mService.showName();
  24.    }
  25.   }
  26.   public void onServiceDisconnected(ComponentName name) 
  27.   {   
  28.    
  29.   }
  30.  };
  31.  @Override
  32.  public boolean onCreateOptionsMenu(Menu menu) {
  33.   // TODO Auto-generated method stub
  34.   super.onCreateOptionsMenu(menu);
  35.   menu.add(0, Menu.FIRST+1, 1, "OpenActivity");
  36.   menu.add(0, Menu.FIRST+2, 2, "StartService");
  37.   menu.add(0, Menu.FIRST+3, 3, "StopService");
  38.   menu.add(0, Menu.FIRST+4, 4, "BindService");
  39.   return true;
  40.  }
  41.  @Override
  42.  public boolean onOptionsItemSelected(MenuItem item) {
  43.   // TODO Auto-generated method stub
  44.   super.onOptionsItemSelected(item);
  45.   switch(item.getItemId())
  46.   {
  47.   case Menu.FIRST + 1:
  48.   {
  49.    this.setTitle("Switch Activity");
  50.    Intent i = new Intent();   
  51.    i.setAction("test_action");  
  52.    if (Tools.isIntentAvailable(this,i))
  53.     this.startActivity(i);
  54.    else
  55.     this.setTitle("the Intent is unavailable!!!");
  56.    break;
  57.   }
  58.   case Menu.FIRST + 2:
  59.   {
  60.    this.setTitle("Start Service");
  61.    //Intent i = new Intent(this, TestService.class);
  62.    Intent i = new Intent();
  63.    i.setAction("start_service");
  64.    this.startService(i);
  65.    break;
  66.   }
  67.   case Menu.FIRST + 3:
  68.   {
  69.    this.setTitle("Stop Service");
  70.    Intent i = new Intent(this, TestService.class);
  71.    this.stopService(i);
  72.    break;
  73.   }
  74.   case Menu.FIRST + 4:
  75.   {
  76.    this.setTitle("Bind Service!");
  77.    Intent i = new Intent(this, TestService.class);
  78.    this.bindService(i, this.sconnection, Context.BIND_AUTO_CREATE);
  79.    
  80.    break;
  81.   }
  82.   }
  83.   return true;
  84.  }
  85.  @Override
  86.     public void onCreate(Bundle savedInstanceState) {
  87.         super.onCreate(savedInstanceState);       
  88.         this.setContentView(R.layout.main);   
  89.     }
  90. }

編譯執(zhí)行,你會發(fā)現(xiàn),是先執(zhí)行onCreate,然后再執(zhí)行onBind,在調(diào)用者的Context.bindService返回時,ServiceConnection的OnConnected并沒有馬上被執(zhí)行。Android服務(wù)遠(yuǎn)程綁定:上述綁定是在調(diào)用者與Service在同一個應(yīng)用程序中的情況,如果分處在不同的程序中,那么,調(diào)用方式又是一另一種情況。我們來看一下。


本文標(biāo)題:詳細(xì)描述Android服務(wù)解說
網(wǎng)址分享:http://www.dlmjj.cn/article/cdpgjdh.html