looper prepare循环中Looper.loop;之后,代码不能运行,是怎么回事

looper prepare  时间:2022-02-24  阅读:()

循环中Looper.loop;之后,代码不能运行,是怎么回事

import .db.DownDatasTask; import .db.OnDownDatasListener; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.provider.Settings.Secure; import android.util.Log; public class MessageService extends Service { private static final String ITEM_MESSAGE = "message"; private static final String ITEM_TITLE = "title"; private static final String ITEM_TIME = "addtime"; //获取消息线程 private Thread mThread = null; //点击查看 //private Intent msgIntent = null; private PendingIntent msgPendingIntent = null; //通知栏消息 private int msgNotificationid = 1000; private Notification msgNotification = null; private NotificationManager msgNotificatiomanager = null; @Override public IBinder onBind(Intent intent) { return null; } @Override public void onStart(Intent intent, int startId) { //初始化 msgNotification = new Notification(); msgNotification.icon = R.drawable.icon1; msgNotification.tickerText = "新消息"; msgNotification.defaults = Notification.DEFAULT_SOUND; msgNotification.flags = Notification.FLAG_AUTO_CANCEL; msgNotificatiomanager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); //开启线程 MsgThread thread=new MsgThread(); mThread=new Thread(thread); mThread.start(); } // @Override // public void onDestroy() { //// System.exit(0); // super.onDestroy(); // } class MsgThread implements Runnable{ public boolean isrunning = true; public void run() { while(isrunning){ try { //休息1分钟 Thread.sleep(60000); //获取服务器消息 Looper.prepare(); Log.v("测试1", "测试1"); loadPushMessage(); Looper.loop(); Log.v("测试2", "测试2"); } catch (InterruptedException e) { e.printStackTrace(); } } } } private void loadPushMessage(){ String mobileid = Secure.getString(getBaseContext().getContentResolver(), Secure.ANDROID_ID); String string_url = Client3Application.url_getData + getResources().getString(R.string.url_push_msg, mobileid); final DownDatasTask down_datas_task_ = new DownDatasTask(); down_datas_task_.execute(string_url); down_datas_task_.setOnDownDatasListener(new OnDownDatasListener() { @Override public void onDownData() { int count = down_datas_task_.getDataCount(); if (count > 0) { Message msg=new Message(); msg.what=1; String string_msg = down_datas_task_.getData(0, ITEM_MESSAGE).toString(); String string_title = down_datas_task_.getData(0, ITEM_TITLE).toString(); String string_time = down_datas_task_.getData(0, ITEM_TIME).toString(); Bundle data = new Bundle(); data.putString("message", string_msg); data.putString("time", string_time); data.putString("title", string_title); msg.setData(data); mHandler.sendMessage(msg); Log.v("测试3", "测试3"); } down_datas_task_.cancel(true); down_datas_task_.clearData(); } }); } private Handler mHandler=new Handler(){ public void handleMessage(Message msg) { int i = msg.what; if(i > 0){ Bundle data = msg.getData(); String string_msg = data.getString("message"); String string_time = data.getString("time"); String string_title = data.getString("title"); Bundle bundle = new Bundle(); Intent msgIntent = new Intent(); bundle.putString("message", string_msg); bundle.putString("time", string_time); bundle.putString("title", string_title); msgIntent.putExtras(bundle); msgIntent.setClass(MessageService.this, MessageActivity.class); msgPendingIntent = PendingIntent.getActivity(MessageService.this,0,msgIntent,0); //更新通知栏 msgNotification.setLatestEventInfo(MessageService.this,"新消息",string_title,msgPendingIntent); msgNotificatiomanager.notify(msgNotificationid, msgNotification); //每次通知完,通知id递增一下,避免消息覆盖掉 msgNotificationid++; } } }; }

搬瓦工香港 PCCW 机房已免费迁移升级至香港 CN2 GIA 机房

搬瓦工最新优惠码优惠码:BWH3HYATVBJW,节约6.58%,全场通用!搬瓦工关闭香港 PCCW 机房通知下面提炼一下邮件的关键信息,原文在最后面。香港 CN2 GIA 机房自从 2020 年上线以来,网络性能大幅提升,所有新订单都默认部署在香港 CN2 GIA 机房;目前可以免费迁移到香港 CN2 GIA 机房,在 KiwiVM 控制面板选择 HKHK_8 机房进行迁移即可,迁移会改变 IP...

Webhosting24:€15/年-AMD Ryzen/512MB/10GB/2TB/纽约&日本&新加坡等机房

Webhosting24是一家始于2001年的意大利商家,提供的产品包括虚拟主机、VPS、独立服务器等,可选数机房包括美国洛杉矶、迈阿密、纽约、德国慕尼黑、日本、新加坡、澳大利亚悉尼等。商家VPS主机采用AMD Ryzen 9 5950X CPU,NVMe磁盘,基于KVM架构,德国机房不限制流量,网站采用欧元计费,最低年付15欧元起。这里以美国机房为例,分享几款套餐配置信息。CPU:1core内存...

LOCVPS:VPS主机全场8折,德国/荷兰/美国KVM终身7折

LOCVPS发来了针对元旦新年的促销活动,除了全场VPS主机8折优惠外,针对德国/荷兰KVM #1/美国KVM#2 VPS提供终身7折优惠码(限量50名,先到先得)。LOCVPS是一家成立于2012年的国人VPS服务商,提供中国香港、韩国、美国、日本、新加坡、德国、荷兰、俄罗斯等地区VPS服务器,基于KVM或XEN架构(推荐优先选择KVM),均选择直连或者优化线路,国内延迟低,适合建站或远程办公使...

looper prepare为你推荐
mdmMDM是什么的简称啊?bloomfilter布隆过滤器既然有错误率,为什么还能应用在key-value系统中?showwindowVB6.0中ShowWindow函数的使用知识库管理系统如何加强知识库的管理溢出隐藏关于CSS样式的问题,怎么可以让div的内容自动换行,溢出隐藏,还要加省略号?最开放的浏览器用的最多的三个浏览器是?查字网拐字换什么偏旁 成新字mindmanager破解版求mindmanager 2019 的注册机备忘录模式Java中常用的设计模式有哪些?请详细说明一下工厂模式。天融信防火墙都说天融信的产品不错,那天融信的下一代防火墙真的是当今最好的防火墙产品了吗?
广东虚拟主机 双线虚拟主机 太原域名注册 免费动态域名 lamp 台湾服务器 vpsio 视频存储服务器 免费smtp服务器 京东商城双十一活动 免费个人空间 免费吧 空间租赁 cdn网站加速 阿里云手机官网 空间申请 网站加速 域名和主机 google搜索打不开 apachetomcat 更多