首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在StopWatch中使用通知

在StopWatch中使用通知
EN

Stack Overflow用户
提问于 2013-05-27 10:14:02
回答 1查看 907关注 0票数 0

我在通知/状态栏中使用秒表。

  • 我在contentTextgetFormattedElapsedTime()一起得到秒表。它可以工作,但当我关闭应用程序时就停止了。即使应用程序关闭了,我怎么能工作呢? 私有NotificationManager m_notificationMgr;私有通知m_notification;// Timer以更新正在进行的通知私有最终mFrequency = 100;//毫秒私有最终int TICK_WHAT = 2;私有Handler mHandler =新Handler() {公共空handleMessage(消息m) { updateNotification();sendMessageDelayed(Message.obtain(this,TICK_WHAT),mFrequency);} };@覆盖公共onCreate() { super.onCreate();Log.d(标记,“创建”);m_stopwatch =新秒表();m_notificationMgr =m_notificationMgr createNotification();} public (){Log.d(标记,“创建通知”);int图标= R.drawable.icon;CharSequence tickerText = "Meb";System.currentTimeMillis();m_notification =新通知(图标,tickerText,时间);m_notification.flags |= Notification.FLAG_ONGOING_EVENT;m_notification.flags |= Notification.FLAG_NO_CLEAR;} public void (){ // Log.d(标记,“更新通知”);上下文上下文= getApplicationContext();CharSequence contentTitle = "Mebr";CharSequence contentText = getFormattedElapsedTime();意图notificationIntent =新意图(this,TimerFragmentActivity.class);PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);//下两行使用m_notification.setLatestEventInfo(上下文、contentTitle、contentText、contentIntent)上的配置初始化通知;} public showNotification() {Log.d(标记,“显示通知”);updateNotification();updateNotification();TICK_WHAT,mFrequency);}公开无效hideNotification() {Log.d(标记,“删除通知”);m_notificationMgr.cancel(NOTIFICATION_ID);mHandler.removeMessages( TICK_WHAT);}
EN

回答 1

Stack Overflow用户

发布于 2013-05-28 04:26:32

您需要从服务中更新您的通知,即使在活动暂停或停止之后,它也可以继续运行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16770918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档