I'm try to make an android exercise of my college and I'm stuck on the alarm part. When you get the time determined by the alarm, I need to send an alert and can open another activity for the notification.
But as the class is already extending the BroadcastReceiver, how can I start another acitivity?
My class are like this:
public class ReceiverAlarme extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//inicia a Activity do Treino
Intent itTreino = new Intent(this, telaTreino.class);
//Does not work
//startActivity(itTreino);
//tentei fazer uma notificação que abrisse o programa, mas não rolou
Notification.Builder notificacao = new Notification.Builder(this);
notificacao.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(android.R.drawable.ic_dialog_email)
.setContentTitle("Agendamento do teste")
.setContentText("Você tem um teste agendado!")
.setContentIntent(PendingIntent.getActivities(getApplicationContext(), 1, itTreino, PendingIntent.FLAG_CANCEL_CURRENT));
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, notificacao.build());
}
}