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++; } } }; }

WebHorizon($10.56/年)256MB/5G SSD/200GB/日本VPS

WebHorizon是一家去年成立的国外VPS主机商,印度注册,提供虚拟主机和VPS产品,其中VPS包括OpenVZ和KVM架构,有独立IP也有共享IP,数据中心包括美国、波兰、日本、新加坡等(共享IP主机可选机房更多)。目前商家对日本VPS提供一个8折优惠码,优惠后最低款OpenVZ套餐年付10.56美元起。OpenVZCPU:1core内存:256MB硬盘:5G NVMe流量:200GB/1G...

飞讯云E5-2678V3 64GB,湖北十堰100G高防物理机330元/月

飞讯云官网“飞讯云”是湖北飞讯网络有限公司旗下的云计算服务品牌,专注为个人开发者用户、中小型、大型企业用户提供一站式核心网络云端部署服务,促使用户云端部署化简为零,轻松快捷运用云计算。飞讯云是国内为数不多具有ISP/IDC双资质的专业云计算服务商,同时持有系统软件著作权证书、CNNIC地址分配联盟成员证书,通过了ISO27001信息安全管理体系国际认证、ISO9001质量保证体系国际认证。 《中华...

sharktech:洛杉矶/丹佛/荷兰高防服务器;1G独享$70/10G共享$240/10G独享$800

sharktech怎么样?sharktech (鲨鱼机房)是一家成立于 2003 年的知名美国老牌主机商,又称鲨鱼机房或者SK 机房,一直主打高防系列产品,提供独立服务器租用业务和 VPS 主机,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹,所有产品均提供 DDoS 防护。不知道大家是否注意到sharktech的所有服务器的带宽价格全部跳楼跳水,降幅简直不忍直视了,还没有见过这么便宜的独立服...

looper prepare为你推荐
showwindowvfp中菜单生成不能运行,提示说要把showwindow属性设为2,不懂求解tvosTVOS系统是什么?waves插件请问下waves9是什么东西,插件吗?memsql如何自己实现一个关系型数据库layoutsubviewsios有没有类似tablayout的控件相似图片搜索怎么找手机上的一张相似图片?watch的过去式wach的过去式疫苗之王“龟毛之王”是什么意思???杭州营销型网站苏州网站推广有哪些?sungard上海sungard 中国区那家公司怎么样啊 谢谢
日本私人vps 香港vps主机 hawkhost 56折 好看的留言 12306抢票攻略 mobaxterm 监控宝 360抢票助手 服务器怎么绑定域名 免费网络电视 hnyd 193邮箱 135邮箱 世界测速 美国堪萨斯 香港亚马逊 带宽租赁 德隆中文网 中国域名 更多