hela första metoden
Kod:
private void setAlarm(){
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
String notydisc = null;
k = timeUntilDate();
int empty = (int) (ID - Notepadv3.notePendingIntents.size() + 1);
for(int i=0;i"mindre än"empty;i++){
Notepadv3.notePendingIntents.add(null);
Notepadv3.noteFutureTimes.add(null);
}
System.out.println(String.format("SÅHÄR STOR ÄR DEN I SETREMINDER!! -----> %d",Notepadv3.notePendingIntents.size()));
Notepadv3.notePendingIntents.set(mRowId.intValue(), contentIntent);
Notepadv3.noteFutureTimes.set(mRowId.intValue(), future.getTimeInMillis());
Toast toast = Toast.makeText(this, String.format("Reminder Set"), Toast.LENGTH_SHORT);
toast.show();
Cursor c = noteDbHelper.fetchNote(mRowId);
startManagingCursor(c);
notydisc = c.getString(c.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE));
Intent intent1 = new Intent(this, NoteNoty.class);
intent1.putExtra("noteid",ID);
intent1.putExtra("notename",notydisc);
contentIntent = PendingIntent.getBroadcast(getApplicationContext(), 0-mRowId.intValue(), intent1, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + k, contentIntent);
}
hela andra metoden, denna finns i klassen NoteNoty som startas av en alarmManager.
Kod:
@Override
public void onReceive(Context context, Intent intent) {
System.out.println(String.format("SÅHÄR STOR ÄR DEN I NOTENOTY!! -----> %d",Notepadv3.notePendingIntents.size()));
Bundle extras = intent.getExtras();
mRowId = extras != null ? extras.getLong("noteid")
: null;
notydisc = extras != null ? extras.getString("notename")
: null;
Intent N = new Intent(context, ShowNote.class);
N.putExtra(NotesDbAdapter.KEY_ROWID,mRowId);
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) context.getSystemService(ns);
notytext = "Note Reminder";
noty = new Notification(R.drawable.statusicon, notytext,System.currentTimeMillis());
N.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
k = 0-mRowId.intValue();
contentIntent = PendingIntent.getActivity(context, k, N, Intent.FLAG_ACTIVITY_NEW_TASK);
noty.setLatestEventInfo(context, notytext, notydisc, contentIntent);
mNotificationManager.cancel(k);
mNotificationManager.notify(k,noty);
//test
Notepadv3.notePendingIntents.set(mRowId.intValue(),null);
Notepadv3.noteFutureTimes.set(mRowId.intValue(),null);
}