当前位置: 首页 > news >正文

招聘网站建设方案模板下载wordpress 页面类型

招聘网站建设方案模板下载,wordpress 页面类型,口碑营销的例子,成都网站建设科技公司1 service是什么 Service是Android系统中的四大组件之一#xff0c;它是一种长生命周期的#xff0c;没有可视化界面#xff0c;运行于后台的一种服务程序。 2 service分类 3 service启动方式 3.1 startService显示启动 // AndroidManifest.xml?xml version1…1 service是什么 Service是Android系统中的四大组件之一它是一种长生命周期的没有可视化界面运行于后台的一种服务程序。 2 service分类 3 service启动方式 3.1 startService显示启动 // AndroidManifest.xml?xml version1.0 encodingutf-8? manifest xmlns:androidhttp://schemas.android.com/apk/res/androidpackagecom.example.myapplicationapplicationandroid:allowBackuptrueandroid:iconmipmap/ic_launcherandroid:labelstring/app_nameandroid:roundIconmipmap/ic_launcher_roundandroid:supportsRtltrueandroid:themestyle/Theme.MyApplicationactivity android:name.StartServiceActivityintent-filteraction android:nameandroid.intent.action.MAIN /category android:nameandroid.intent.category.LAUNCHER //intent-filter/activityservice android:name.StartService //application/manifest// StartSeviceActivity.java package com.example.myapplication;import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import androidx.appcompat.app.AppCompatActivity;//import com.ttit.helloworld.R;public class StartServiceActivity extends AppCompatActivity {private Button start;private Button stop;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.service_layout);start (Button) findViewById(R.id.btnstart);stop (Button) findViewById(R.id.btnstop);final Intent intent new Intent(StartServiceActivity.this, StartService.class);start.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {startService(intent);}});stop.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {stopService(intent);}});} }// StartService.java package com.example.myapplication;import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log;import android.os.Bundle;public class StartService extends Service {private final String TAG service;//必须要实现的方法Overridepublic IBinder onBind(Intent intent) {Log.e(TAG, onBind方法被调用!);return null;}//Service被创建时调用Overridepublic void onCreate() {Log.e(TAG, onCreate方法被调用!);super.onCreate();}//Service被启动时调用Overridepublic int onStartCommand(Intent intent, int flags, int startId) {Log.e(TAG, onStartCommand方法被调用!);return super.onStartCommand(intent, flags, startId);}//Service被关闭之前回调Overridepublic void onDestroy() {Log.e(TAG, onDestory方法被调用!);super.onDestroy();} }// service_layout.xml?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentButtonandroid:idid/btnstartandroid:layout_width0dpandroid:layout_weight1android:layout_heightwrap_contentandroid:text开始服务/Buttonandroid:idid/btnstopandroid:layout_width0dpandroid:layout_weight1android:layout_heightwrap_contentandroid:text停止服务//LinearLayout1 通过按钮开始服务启动service final Intent intent new Intent(StartServiceActivity.this, StartService.class);start.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {startService(intent);}});2 创建StartService 继承service类 public class StartService extends Service在StartService中实现 onBindonCreateonStartCommand onDestroy方法 3 在AndroidManifest.xml 清单文件中注册 service android:name.StartService /4 运行结果 点击开始服务运行结果如下 多次点击开始服务运行结果如下 点击停止服务运行结果如下 3.2 bindService绑定启动 //AndroidManifest.xml?xml version1.0 encodingutf-8? manifest xmlns:androidhttp://schemas.android.com/apk/res/androidpackagecom.example.myapplicationapplicationandroid:allowBackuptrueandroid:iconmipmap/ic_launcherandroid:labelstring/app_nameandroid:roundIconmipmap/ic_launcher_roundandroid:supportsRtltrueandroid:themestyle/Theme.MyApplicationactivity android:name.BindServiceActivityintent-filteraction android:nameandroid.intent.action.MAIN /category android:nameandroid.intent.category.LAUNCHER //intent-filter/activityservice android:name.BindService //application/manifest// BindServiceActivity.java package com.example.myapplication; 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; import android.widget.Button; import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;public class BindServiceActivity extends AppCompatActivity {private Button btnbind;private Button btncancel;private Button btnstatus;//保持所启动的Service的IBinder对象,同时定义一个ServiceConnection对象private BindService.MyBinder binder;private ServiceConnection conn new ServiceConnection() {//Activity与Service断开连接时回调该方法Overridepublic void onServiceDisconnected(ComponentName name) {Log.e(service, ------Service DisConnected-------);}//Activity与Service连接成功时回调该方法Overridepublic void onServiceConnected(ComponentName name, IBinder service) {Log.e(service, ------Service Connected------ - );binder (BindService.MyBinder) service;}};Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.bind_service_layout);btnbind (Button) findViewById(R.id.btnbind);btncancel (Button) findViewById(R.id.btncancel);btnstatus (Button) findViewById(R.id.btnstatus);final Intent intent new Intent(BindServiceActivity.this, BindService.class);btnbind.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {//绑定servicebindService(intent, conn, Service.BIND_AUTO_CREATE);}});btncancel.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {//解除service绑定unbindService(conn);}});btnstatus.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {Toast.makeText(getApplicationContext(), Service的count的值为: binder.getCount(), Toast.LENGTH_SHORT).show();}});}Overrideprotected void onDestroy() {super.onDestroy();unbindService(conn); // 销毁Activity时需要解绑Service} }// BindService package com.example.myapplication;import android.app.Service; import android.content.Intent; import android.os.Binder; import android.os.IBinder; import android.util.Log;public class BindService extends Service {private final String TAG service;private int count;private boolean quit;//定义onBinder方法所返回的对象private MyBinder binder new MyBinder();public class MyBinder extends Binder {public int getCount() {return count;}}//必须实现的方法,绑定改Service时回调该方法Overridepublic IBinder onBind(Intent intent) {Log.e(TAG, onBind方法被调用!);return binder;}//Service被创建时回调Overridepublic void onCreate() {super.onCreate();Log.e(TAG, onCreate方法被调用!);//创建一个线程动态地修改count的值new Thread() {public void run() {while (!quit) {try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}count;Log.e(TAG, count count);}}}.start();}//Service断开连接时回调Overridepublic boolean onUnbind(Intent intent) {Log.e(TAG, onUnbind方法被调用!);return true;}//Service被关闭前回调Overridepublic void onDestroy() {super.onDestroy();this.quit true;Log.e(TAG, onDestroyed方法被调用!);}Overridepublic void onRebind(Intent intent) {Log.e(TAG, onRebind方法被调用!);super.onRebind(intent);} }layout截图如下 运行结果如下 点击绑定SERVICE: 4 service生命周期 startService启动的生命周期 onCreate() 当Service第一次被创建时由系统调用。 onStartCommand() 当startService方法启动Service时该方法被调用。 onDestroy() 当Service不再使用时由系统调用。 注意一个startService只会创建一次销毁一次但可以开始多次因此onCreate()和onDestroy()方法只会被调用一次而onStartCommand()方法会被调用多次。 bindService启动的生命周期 onCreate() 当Service被创建时由系统调用。 onBind() 当bindService方法启动Service时该方法被调用。 onUnbind() 当unbindService方法解除绑定时该方法被调用。 onDestroy() 当Service不再使用时由系统调用。 注意一个bindService可以创建多次销毁多次重复使用。 5 service和thread的区别 结论Service和Thread之间没有任何关系 之所以有不少人会把它们联系起来主要因为Service的后台概念 后台的定义后台任务运行完全不依赖UI即使Activity被销毁或者程序被关闭只要进程还在后台任务就可以继续运行 其实二者存在较大的区别如下图 一般来说会将Service和Thread联合着用即在Service中再创建一个子线程工作线程去处理耗时操作逻辑如下代码 Override public int onStartCommand(Intent intent, int flags, int startId) { //新建工作线程new Thread(new Runnable() { Override public void run() { // 开始执行后台任务 } }).start(); return super.onStartCommand(intent, flags, startId); } class MyBinder extends Binder { public void service_connect_Activity() { //新建工作线程new Thread(new Runnable() { Override public void run() { // 执行具体的下载任务 } }).start(); } }
http://www.zqtcl.cn/news/94626/

相关文章:

  • 网站制作app开发公司网站建设 英文
  • 毕业设计网页制作网站建设网站预约挂号怎么做
  • 河东天津网站建设永州做网站的公司
  • 网页制作与网站建设填空题免费的企业邮箱怎么申请
  • 智慧农业网站建设沈阳建设信息网
  • 永久免费素材网站个人网站域名所有权
  • 做网站都需要什么工具网站开发培训哪里好
  • 做网站里面的图片像素要求安徽 网站建设
  • 电子商务推广网站wordpress小程序搭建
  • 张家港网站开发培训广告代理那些平台可以给网站做外链
  • 搞一个公司网站得多少钱中国航天空间站最新消息
  • php移动网站开发微商做图王官方网站
  • 制作网站中英文字体不能为网页设计与制作教程试题
  • 网站建设与管理案例柳洪轶wordpress学校站模板
  • 湖北省和住房建设厅官方网站自媒体专业
  • 榆林网站开发自己建设购物网站
  • 新材建设局网站百度提问首页
  • 网站优化网站建设栅格布局 网站设计
  • 网站建设销售前景网站手机开
  • 网站建站 用户注册北京网站建设方案报价
  • jsp做网站 案例网站模板 招聘
  • 德州建设银行兑换网站服务器网站跳转怎么做的
  • 金华专业做网站公司湖南网站建设服务
  • 企业网站设计沈阳苏宁电器网站建设特点分析
  • 建设工程类公司网站易语言可以做api网站对接吗
  • 青岛做网站皆赴青岛博wordpress 数据库 备份
  • 外贸公司网站空间哈尔滨seo优化专注
  • 建筑行业综合查询平台优化推广联盟
  • 北京管庄网站建设公司开平网站制作
  • 如何做销售直播网站最专业网站建设