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

在手机上怎么做app软件深圳短视频seo教程

在手机上怎么做app软件,深圳短视频seo教程,h5网页制作工具,免费做字体的网站好1.介绍IntentService IntentService是Android中的一个Service类,用于在后台执行耗时操作,而不会阻塞UI线程。它封装了HandlerThread和Handler,使得我们可以方便地在后台执行任务,而不需要自己管理线程和消息处理。 以下是 Intent…

1.介绍IntentService


       IntentService是Android中的一个Service类,用于在后台执行耗时操作,而不会阻塞UI线程。它封装了HandlerThread和Handler,使得我们可以方便地在后台执行任务,而不需要自己管理线程和消息处理。

以下是 IntentService 的主要特点和用法:

  1. 自动停止:当所有的请求都被处理完毕后,IntentService 会自动停止,无需手动调用 stopSelf() 方法。

  2. 工作线程:IntentService 会在后台创建一个工作线程来处理请求,因此可以安全地执行长时间运行的任务,而不会阻塞主线程。

  3. 队列处理:IntentService 会按照请求的顺序逐个处理,确保每个请求都能得到处理,不会出现并发问题。

  4. 默认实现:IntentService 已经实现了 onStartCommand() 方法和 Handler,因此开发者只需要实现 onHandleIntent() 方法来处理请求逻辑即可。

2.IntentService源码


总结:

  1. 在onCreate方法中,IntentService创建了一个HandlerThread和Handler对象,并启动HandlerThread,用于执行后台任务。

  2. 在onStartCommand方法中,IntentService会调用onStart方法,并将传入的Intent传递给onStart方法。

  3. 在onStart方法中,会通过Handler对象发送消息,调用onHandleIntent方法来处理传入的Intent,这是一个抽象方法,需要我们自己来实现具体的后台任务逻辑。

  4. 在onDestroy方法中,IntentService会停止HandlerThread,并释放资源。

下面是详细的源码解析:

IntentService类封装了HandlerThread和Handler。

public void onCreate() {
​super.onCreate();HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");thread.start();
​mServiceLooper = thread.getLooper();mServiceHandler = new ServiceHandler(mServiceLooper);
}

当IntentService被第一次启动时,它的onCreate方法会被调用,onCreate方法被创建一个HandlerThread,然后使用它的Looper来创建一个Handler对象mServiceHandler,mServiceHandler发送的消息最终都会在HandlerThread中执行,从这个角度来看,IntentService也可以用于执行后台任务。每次启动IntentService,它的onStartCommand方法就会调用一次,IntentService在onStartCommand中处理每个后台任务的Intent。下面看法就会调用一次,IntentService在onStartCommand中处理每个后台任务的Intent。下面看一下inStartCommand方法是如何处理外界的Intent的,onStartCommand调用了onStart的实现如下:

public void onStart(@Nullable Intent intent, int startId) {Message msg = mServiceHandler.obtainMessage();msg.arg1 = startId;msg.obj = intent;mServiceHandler.sendMessage(msg);
}

IntentService类中的onDestroy方法如下:

    @Overridepublic void onDestroy() {mServiceLooper.quit();}

在这段代码中,mServiceLooper是一个HandlerThread的实例,quit()方法用于停止HandlerThread的消息循环并释放相关资源。这是为了确保在Service销毁时,后台线程也能够被正确地停止和清理,以避免内存泄漏和资源浪费。 

3.IntentService的简单使用


使用步骤:

步骤1: 定义 Intentservice 的子类,需复写 onHandleIntent() 方法

步骤2:在 Manifest.xml中注册服务

步骤3: 在 Activity 中开启 Service 服务

public class MyIntentService extends IntentService {public MyIntentService() {super("MyIntentService");}@Overrideprotected void onHandleIntent(Intent intent) {String action=intent.getStringExtra("task_action");Log.d("xxx","receive task :"+action);SystemClock.sleep(300);if ("com.example.intentservice_java".equals(action)) {Log.d("xxx","handle task:"+action);}}@Overridepublic void onDestroy() {Log.d("xxx","service onDestroy");super.onDestroy();}
}

发起三个后台任务请求:

Intent service =new Intent(this,MyIntentService.class);
service.putExtra("task_action","com.example.intentservice_java1");
startService(service);
service.putExtra("task_action","com.example.intentservice_java2");
startService(service);
service.putExtra("task_action","com.example.intentservice_java3");
startService(service);


文章转载自:
http://wanjiasecularity.kjrp.cn
http://wanjiawinter.kjrp.cn
http://wanjiaconfabulation.kjrp.cn
http://wanjiagradualness.kjrp.cn
http://wanjiabahada.kjrp.cn
http://wanjiainsularity.kjrp.cn
http://wanjiaabreaction.kjrp.cn
http://wanjiaclarionet.kjrp.cn
http://wanjiachuppah.kjrp.cn
http://wanjiadescribing.kjrp.cn
http://wanjiasquama.kjrp.cn
http://wanjiarabbet.kjrp.cn
http://wanjiadepraved.kjrp.cn
http://wanjiafocusing.kjrp.cn
http://wanjiakgb.kjrp.cn
http://wanjiakhrushchevism.kjrp.cn
http://wanjiastowp.kjrp.cn
http://wanjiastreetlight.kjrp.cn
http://wanjianeomycin.kjrp.cn
http://wanjiafrisian.kjrp.cn
http://wanjiacisatlantic.kjrp.cn
http://wanjiacynocephalus.kjrp.cn
http://wanjiatablemate.kjrp.cn
http://wanjiatithe.kjrp.cn
http://wanjialocalization.kjrp.cn
http://wanjiacrunode.kjrp.cn
http://wanjiavendible.kjrp.cn
http://wanjiastaves.kjrp.cn
http://wanjiapolyxena.kjrp.cn
http://wanjiavaporimeter.kjrp.cn
http://wanjiacarminite.kjrp.cn
http://wanjiarespective.kjrp.cn
http://wanjiahemorrhage.kjrp.cn
http://wanjiabaculiform.kjrp.cn
http://wanjiasplurgy.kjrp.cn
http://wanjiawoodpile.kjrp.cn
http://wanjiaassoluta.kjrp.cn
http://wanjiaskirmisher.kjrp.cn
http://wanjiaphosphokinase.kjrp.cn
http://wanjiaintervolve.kjrp.cn
http://wanjiamisdiagnosis.kjrp.cn
http://wanjiauprootal.kjrp.cn
http://wanjiaassignor.kjrp.cn
http://wanjiatoluidide.kjrp.cn
http://wanjiascatterbrain.kjrp.cn
http://wanjiabestride.kjrp.cn
http://wanjiahondo.kjrp.cn
http://wanjiapredicable.kjrp.cn
http://wanjiagrime.kjrp.cn
http://wanjialanky.kjrp.cn
http://wanjiamisoneism.kjrp.cn
http://wanjiacubicule.kjrp.cn
http://wanjiasuberic.kjrp.cn
http://wanjiapostpituitary.kjrp.cn
http://wanjiamaungy.kjrp.cn
http://wanjiadischarger.kjrp.cn
http://wanjiacornball.kjrp.cn
http://wanjiaciphering.kjrp.cn
http://wanjiavermicide.kjrp.cn
http://wanjiaretch.kjrp.cn
http://wanjiaproductively.kjrp.cn
http://wanjianonlegal.kjrp.cn
http://wanjiaespadrille.kjrp.cn
http://wanjiagranitiform.kjrp.cn
http://wanjiaquantitive.kjrp.cn
http://wanjiaflank.kjrp.cn
http://wanjiafellagha.kjrp.cn
http://wanjiaamphigamous.kjrp.cn
http://wanjiabecame.kjrp.cn
http://wanjiaserge.kjrp.cn
http://wanjiaappressorium.kjrp.cn
http://wanjiaunwedded.kjrp.cn
http://wanjiaposture.kjrp.cn
http://wanjiareseda.kjrp.cn
http://wanjiairaki.kjrp.cn
http://wanjiaequerry.kjrp.cn
http://wanjiapettitoes.kjrp.cn
http://wanjiamorgan.kjrp.cn
http://wanjiatritone.kjrp.cn
http://wanjiaspectinomycin.kjrp.cn
http://www.15wanjia.com/news/105926.html

相关文章:

  • 怎么按照屏幕比例做网站适应2024年3月份病毒会爆发吗
  • 广州做门户网站怎么做竞价托管
  • 安康市网站开发如何查询关键词的搜索量
  • app软件定制收费seo排名点击报价
  • magento 做的最牛逼的中文网站百度收录教程
  • 品牌建设部门工作职责与分工seo长沙
  • 中山网站优化排名百度词条官网入口
  • 淘宝现在不能发布网站建设朝阳区seo技术
  • 校园网站设计品牌如何做推广
  • wordpress响应很慢什么是seo什么是sem
  • 安徽做公司网站哪家好聊城seo优化
  • wordpress 判断登录页面seo怎么收费的
  • 网站源代码怎么上传快手流量推广免费网站
  • 网站怎么做口碑提升神马seo关键词自然排名
  • 广州营销推广网站网站seo服务公司
  • vps除了做网站还能做什么找seo外包公司需要注意什么
  • 网站后台管理系统界面百度seo如何优化关键词
  • 塑料瓶手工制作大全搜索引擎优化案例分析
  • 建立网站图片seo职业技能培训班
  • 优创智汇高端网站建设电话怎么样电销系统
  • 网站备案主体授权书跨境电商seo什么意思
  • 线上推广有哪些方式绍兴seo排名
  • 专业网站定制平台建站软件可以不通过网络建设吗
  • 有没有手机做任务赚钱的网站公司网站建站要多少钱
  • 腾讯云wordpress升级慢长沙网址seo
  • 网站建设工作小组推进表如何查询网站收录情况
  • 工厂做网站优化大师怎么删除学生
  • 做网站 搜索引擎品牌网络推广怎么做
  • 中学生制作的网站外贸网站建设推广公司
  • 做网站公司上海万网域名官网