Note that there are some explanatory texts on larger screens.

plurals
  1. POsetting Multiple alarms in different activities
    primarykey
    data
    text
    <p>I am newbie programmer, I am creating an alarm app containing multiple activities, each capable of setting 1 alarm. I am using same alarm broadcastreciever for all the activities and I use notification manager inside the broadcast reciever. I pass different ids for different activities that use the broadcastreceiver for notify command using getextras. When I try out the application, the alarm which gets shown seems to be of the activity whose button i pressed the latest. Also there is a +-1 min error between set time and notification time .Can anyone suggest any other change I can make so I can get multiple notification instead of just one and at the exact set time. Thanks in advance for the answer. :)</p> <p>here is the alarm receiver code:</p> <pre><code>public void onReceive(Context context, Intent intent) { Toast.makeText (context, R.string.app_name, Toast.LENGTH_SHORT).show(); String Title=intent.getStringExtra("title"); String days=intent.getStringExtra("days"); int id=intent.getIntExtra("id", 0); NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.ic_launcher,days,System.currentTimeMillis()); // Intent i= new Intent(context,MainActivity.class); PendingIntent p= PendingIntent.getActivity(context,0,intent,0); notify.setLatestEventInfo(context, Title, days, p); nm.notify(id,notify); </code></pre> <p>Here is the <code>main.java</code> code inside <code>onclicklistener</code>:</p> <pre><code> AlarmManager am = null; PendingIntent appIntent = null; String days = et.getText().toString(); int daynum = java.lang.Integer.parseInt(days); String s2 = (String) ss.getSelectedItem(); Calendar c = Calendar.getInstance(); Calendar c1=Calendar.getInstance(); int y = 2013, m = Calendar.NOVEMBER, d = 29, h = 11, i = 6; if (s2.equals("Morning")) { h = 7; } else if (s2.equals("Afternoon")) { h = 12; } else if (s2.equals("Evening")) { h = 17; } else if (s2.equals("Night")) { h = 21; } h=12;i=6; c.set(y, m, d, h, i,0); c1.setTimeInMillis(c.getTimeInMillis()-daynum*24*60*60*1000); button.setText(c1.toString()); Context context =main.this; Intent intent = new Intent(context, AlarmReceiver2.class); intent.putExtra("title", "title"); intent.putExtra("days",days+" days left"); intent.putExtra("id",1); appIntent = PendingIntent.getBroadcast(context, 0, intent, 0); am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), appIntent); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload