作者ivanf10710 (Ivan)
看板AndroidDev
标题Re: [问题] 请问该如何建置每周重复的AlarmManager
时间Thu Jul 19 16:19:48 2012
Mia谢谢您的解答,还有一个问题想请教您一下
我的闹钟触发的method如下:
private void fireTime(long firetime) {
AlarmAnager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent i = new Intent();
i.setAction("go");
PendingIntent sender = PendingIntent.getBroadcast(this, 0 , intent, 0);
alram.setRepeating(AlarmManager.RTC_WAKEUP, firetime,
5*1000, sender);
}
MyReceiver的onReceive如下:
Intent i = new Intent();
if(intent.getAction().equals("go")) {
Toast.makeText(context, "gogogo", Toast.LENGTH_LONG).show();
}
Menifest也注册了
<receiver android name = ".MyReciever">
<intent - filter>
<action android:name = "go">
</intent - filter>
</receiver>
但是run起来MyReceiver却都没收到广播,不会执行Toast
我有哪个地方漏掉吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.132.134.150
1F:→ hijamoya:确定你的context是谁... 有时候他根本不存在 你可以先用 07/19 19:03
2F:→ hijamoya:LOG来看看他有没有印出来 07/19 19:03
3F:→ hijamoya:如果有的话就代表广播是有 而只是toast的context的问题 07/19 19:03
4F:推 sdyy:你receiver里面怎麽会有Intent i = new Intent(); 07/19 22:32
5F:→ sdyy:你这样下面那行永远都不会执行阿 07/19 22:33
6F:→ sdyy:应该是直接接receiver的intent才对 07/19 22:34
7F:→ ivanf10710:还很新听不太懂S大说的,可以解释一下吗@@? 07/19 23:03
8F:→ ivanf10710:感谢H大跟S大,两位的回答刚好解决我的问题 07/20 00:06
9F:→ ivanf10710:S大说的把new Intent()去掉我懂了!!是要以receiver 07/20 00:07
10F:→ ivanf10710:的onRecieve()里的intent来用才对 07/20 00:08
11F:→ ivanf10710:收到以後就说现H大说得事情了,context是错的 07/20 00:09
12F:→ ivanf10710:我原本是设在按下Button才会发送广播,但是他一RUN起来 07/20 00:09
13F:→ ivanf10710:就直接show Toast了-.-但是我还没解决context的问题 07/20 00:10