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

Megalayer美国独立服务器新用户首月优惠350元(30M优化不限流量)

Megalayer 商家在开始看到有提供香港服务器、香港站群服务器的时候有介绍过,后来就一直没有怎么关注。但是前几天有看到网友使用到他们家的美国独立服务器问其如何的,但是我没有使用过就不好评论,这不前几天也有介绍到Megalayer美国独立服务器。以及我们也有看到商家有提供美国站群服务器和美国大带宽服务器产品,可选30M不限制流量CN2优化线路,以及100M不限制流量国际带宽线路。新年元旦后,Me...

特网云(1050元),IP数5 个可用 IP (/29) ,美国高防御服务器 无视攻击

特网云特网云为您提供高速、稳定、安全、弹性的云计算服务计算、存储、监控、安全,完善的云产品满足您的一切所需,深耕云计算领域10余年;我们拥有前沿的核心技术,始终致力于为政府机构、企业组织和个人开发者提供稳定、安全、可靠、高性价比的云计算产品与服务。官方网站:https://www.56dr.com/ 10年老品牌 值得信赖 有需要的请联系======================特网云美国高防御...

Megalayer优化带宽和VPS主机主机方案策略 15M CN2优化带宽和30M全向带宽

Megalayer 商家主营业务是以独立服务器和站群服务器的,后来也陆续的有新增香港、菲律宾数据中心的VPS主机产品。由于其线路的丰富,还是深受一些用户喜欢的,有CN2优化直连线路,有全向国际线路,以及针对欧美的国际线路。这次有看到商家也有新增美国机房的VPS主机,也有包括15M带宽CN2优化带宽以及30M带宽的全向线路。Megalayer 商家提供的美国机房VPS产品,提供的配置方案也是比较多,...

looper prepare为你推荐
rbf神经网络RBF神经网络和BP神经网络有什么区别foxmail邮箱注册如何注册FOXMAIL邮箱的帐号啊?电子日历怎样调整电子日历上的时间拓扑关系简述空间数据的拓扑关系及其对GIS数据处理和空间分析有何重要意义?丁奇赛尔号丁奇技能表,带等级,刷什么学习力好?ruby语言Ruby是 什么意思数据分析报告范文800字统计分析报告图片存储怎么设置图片的保存类型图片存储如何将图片保存下来pci数据捕获和信号处理控制器华硕pci数据捕获和信号处理控制器出现黄色叹号该下载什么驱动
vps侦探 域名备案收费吗 阿里云os winscp 香港cdn parseerror 免费静态空间 丹弗 合肥鹏博士 华为网络硬盘 免费个人空间申请 河南m值兑换 工作站服务器 cdn联盟 hkg 双线机房 新加坡空间 云服务器比较 lamp什么意思 免费个人网页 更多