Android service 小研究
????? 最近同學搞起了Android開發(fā),自己也撿起來這個玩意來看看。這里先研究一下service
????? Service是安卓系統(tǒng)提供的四種組件之一,功能與activity類似,只不過沒有activity 的使用頻率高。顧名思義Service就是運行在后臺的一種服務程序一般很少與用戶交互,沒有可視化界面。
????? 定義一個service非常簡單,只要繼承就可以了,實現其中的那些方法就可以了。service必須在AndroidManifest.xml配置文件中定義
<service?? android:name=”myservice”>
<intent-filter>
<action android:name=”com.houyewei.action.MY_SERVICE”/>
</intent-filter>
</service>
intent-filter制定如何訪問該service
onBind(Intent intent):是必須實現的一個方法返回接口
onCreate():當service第一次被創(chuàng)建有系統(tǒng)調用
onStart(Intent intent ,int startid):當通過startservice()方法啟動service是該方法被調用
?
onDestory():當service不再使用,系統(tǒng)調用該方法
?
創(chuàng)建一個service代碼
?
public classs Myservice extends Service
{
?? public IBinder onBind(Intent intent)
{
??? return null;
}
? public void onCreate()
??? {
????? super.onCreate();
??? }
? public void onStart(Intent intent ,int startId)
?? {
???? super.onStart(intent,startId);
?? }
?? public void onDestory()
?? {
????? super.onDestory();
???
?? }
}
轉載于:https://www.cnblogs.com/houyewei/archive/2011/12/03/2274915.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Android service 小研究的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用tushare数据进行backtra
- 下一篇: github客户端从gitLab下拉取代