Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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

Java
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;
Posted
Updated 27-Mar-14 9:47am
v3
Comments
Sergey Alexandrovich Kryukov 27-Mar-14 12:34pm    
Eclipse is only the IDE. You cannot talk about "changing... in android eclipse"...
—SA
Behno0o0oD 27-Mar-14 15:46pm    
tnx for correcting me
Sergey Alexandrovich Kryukov 27-Mar-14 15:49pm    
You are welcome.
—SA
[no name] 27-Mar-14 15:55pm    
"as you see I want to increase i".... no, I do not see that at all. I also do not see where you ask a question or describe a problem. You declared i and assigned it a value of 0 but you do not use it anywhere.
Behno0o0oD 27-Mar-14 16:05pm    
the problem is that I don't know which function is called every time the alarm fires.
If I know the function, I'll use "i" in that:)
tnx for your answer

1 solution

You can increase i in
onReceive()
 
Share this answer
 
Comments
Behno0o0oD 29-Mar-14 0:44am    
It does not work!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900