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

免费注册宝塔面板账户赠送价值3188礼包适合购买抵扣折扣

对于一般的用户来说,我们使用宝塔面板免费版本功能还是足够的,如果我们有需要付费插件和专业版的功能,且需要的插件比较多,实际上且长期使用的话,还是购买付费专业版或者企业版本划算一些。昨天也有在文章中分享年中促销活动。如今我们是否会发现,我们在安装宝塔面板后是必须强制我们登录账户的,否则一直有弹出登录界面,我们还是注册一个账户比较好。反正免费注册宝塔账户还有代金券赠送。 新注册宝塔账户送代金券我们注册...

香港站群多ip服务器多少钱?零途云香港站群云服务器怎么样?

香港站群多ip服务器多少钱?想做好站群的SEO优化,最好给每个网站都分配一个独立IP,这样每个网站之间才不会受到影响。对做站群的站长来说,租用一家性价比高且提供多IP的香港多ip站群服务器很有必要。零途云推出的香港多ip站群云服务器多达256个IP,可以满足站群的优化需求,而且性价比非常高。那么,香港多ip站群云服务器价格多少钱一个月?选择什么样的香港多IP站群云服务器比较好呢?今天,小编带大家一...

A400:36元/季,16.8/月kvm架构,线路优质,延迟低

A400互联是一家成立于2020年的商家,主要推行洛杉矶服务器采用kvm架构,线路优质,延迟低,稳定性高!全场产品对标腾讯云轻量,服务器线路有有美国洛杉矶cn2_gia、香港cn2+cmi,目前推行的vps服务器均为精心挑选的优质线路机房,A400互联推出了夏季优惠洛杉矶5折、香港7折促销活动,质量可靠,价格实惠!二:优惠码洛杉矶五折优惠码:20210620香港cn2七折优惠码:0710三、优惠方...

looper prepare为你推荐
ipad怎么分屏ipad如何分屏使用2020weakhashmapjava中几种Map在什么情况下使用,并简单介绍原因及原理showwindowvb ShowWindow 的使用方法 隐藏/显示 指定窗口 (完整代码)谢谢查字网“很”去掉双人旁读什么?mindmanager破解版谁有MindManager破解版的电子日历墙上挂的电子日历不显示怎么维修deviceidAndroid里DeviceId和AndroidId都是什么意思?faq是什么意思fans是什么意思?弹幕网站谁能给我解释一下什么叫A站,什么叫B站?都是啥网站?layoutsubviews如何自定义UISearchBar?
虚拟主机是什么 北京域名空间 三级域名网站 singlehop 优惠码 香港托管 免费ftp空间 英语简历模板word seovip 火车票抢票攻略 云图标 帽子云 183是联通还是移动 阿里校园 网络空间租赁 天翼云盘 网游服务器 美国独立日 便宜空间 石家庄服务器托管 更多