-1

i need to make a shedule reminder which will notify every day at several specific times here just for example i am calling it twice but the twice call to setInexactRepeating is not working for me the notification i get is only because first call of setInexactRepeating please tell me what should i do

here is my code..

package aadil.reminder.health;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
NotificationManager nm;
AlarmManager am;
Calendar clndr=Calendar.getInstance();

static final int unique=18493;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

am=(AlarmManager) getSystemService(ALARM_SERVICE);

//Toast.makeText(getApplicationContext(), "button clicked", Toast.LENGTH_LONG).show();
Intent intent = new Intent("intent.AADIL_INTENT");
intent.putExtra("msg", "blah blah");
intent.putExtra("msg", "class 2");
//intent.putExtra("msg1", "blah msg 2");
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 1, intent, 0);
PendingIntent p2 = PendingIntent.getBroadcast(getApplicationContext(), 1, intent, 0);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+2000,3000,         pi);

//intent.putExtra("msg", "class 1");

am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+3000,2000, p2);
}
}

package aadil.reminder.health;

public class AlarmReciever extends BroadcastReceiver {

        int i = 0;
    @Override
    public void onReceive(Context arg0, Intent arg1) {
            NotificationManager nm = (NotificationManager)     arg0.getSystemService(arg0.NOTIFICATION_SERVICE);

        Intent intent=new Intent().addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pi= PendingIntent.getBroadcast(arg0, 0, intent, 0);

            String body= arg1.getExtras().getString("msg");
        String title="wake up";
        Notification n=new Notification(R.drawable.ic_launcher, body,    System.currentTimeMillis());
        n.setLatestEventInfo(arg0, title, body, pi);
        n.flags = n.flags | n.FLAG_AUTO_CANCEL;
        n.defaults=Notification.DEFAULT_ALL;
        nm.notify(i,n);
        i++;
    }



}
Aadil Ahmad
  • 139
  • 9

1 Answers1

0

Your two pending intents are identical, so the latter call will replace the former pending intent in the scheduled alarms list. Try creating p2 from a 2nd Intent instead of using the same intent to create both PendingIntent.

Also, your requested interval is not one of the constants defined in AlarmManager package, such as AlarmManager.INTERVAL_FIFTEEN_MINUTES. If the interval requested doesn't match one of these constants the alarm will be scheduled by Android using setRepeating() (at least on SDK <19), thus losing the power saving benefits of setInexactRepeating().

You may also find my other answer here useful.

Community
  • 1
  • 1
fingertricks
  • 219
  • 2
  • 6