本文介绍了如何每分钟更换一个计数器(android开发)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。
我正在使用闹钟管理器每分钟完成一些任务,
我每次发出此警报时都需要增加一个计数器。 br />
任何帮助将不胜感激
tnx提前
Hi every one
I am using alarm manager in order to do some tasks every minute,
I need to increase a counter every time I fire this alarm.
any help would be appreciated
tnx in advance
public class AlarmManagerBroadcastReceiver extends BroadcastReceiver {
private int i = 0;
@Override
public void onReceive(Context context, Intent intent) {
PowerManager pm = (PowerManager) context
.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, "YOUR TAG");
wl.acquire();
Bundle extras = intent.getExtras();
StringBuilder msgStr = new StringBuilder();
if (extras != null && extras.getBoolean(ONE_TIME, Boolean.FALSE)) {
msgStr.append("One time Timer : ");
}
Format formatter = new SimpleDateFormat("hh:mm:ss a");
msgStr.append(formatter.format(new Date()));
Toast.makeText(context, msgStr, Toast.LENGTH_LONG).show();
wl.release();
}
public void SetAlarm(Context context) {
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
intent.putExtra(ONE_TIME, Boolean.FALSE);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
60*1000, pi);
}
as you see I want to increase i;
推荐答案
onReceive()
这篇关于如何每分钟更换一个计数器(android开发)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!