日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

赵雅智:service_startService生命周期

發布時間:2023/12/10 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 赵雅智:service_startService生命周期 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


案例演示

布局文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="${packageName}.${activityClass}" ><Buttonandroid:id="@+id/btn_start"android:layout_width="match_parent"android:layout_height="wrap_content"android:onClick="click"android:text="context.startService" /><Buttonandroid:id="@+id/btn_stop"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@+id/btn_start"android:onClick="click"android:text="context.strpService" /></RelativeLayout>


注冊service

<?

xml version="1.0" encoding="utf-8"?

> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android_servicedemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.android_servicedemo.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name="ServiceTese" android:permission="com.example.permission.servers" > <intent-filter> <action android:name="com.example.serversdemo.action" /> </intent-filter> </service> </application> </manifest>


主activity

package com.example.android_servicedemo;import android.app.Activity; import android.app.Service; import android.content.ComponentName; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.view.View;public class MainActivity extends Activity {private Intent service;MyConn myConn;public static final String TAG = "MainActivity";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 隱士意圖的啟動service = new Intent();service.setAction("com.example.serversdemo.action");}public void click(View v) {int id = v.getId();switch (id) {/** 啟動服務*/case R.id.btn_start:this.startService(service);break;/** 停止服務*/case R.id.btn_stop:this.stopService(service);break;default:break;}}}

執行結果

點擊context.startService--->點擊context.stopService。

生命周期為


點擊context.startService--->home鍵--->點擊context.startService--->點擊context.startService...--->點擊context.stopService


onbindService見http://blog.csdn.net/zhaoyazhi2129/article/details/32712073

轉載于:https://www.cnblogs.com/blfshiye/p/5130730.html

總結

以上是生活随笔為你收集整理的赵雅智:service_startService生命周期的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。