I'm building a notification service in my app and for that, I have created a layout that allows the user to input a date(via date picker) and time(via time picker) and the values get displayed in TextViews. I have two classes, one is the main(which implements the layout)
the other one is the BroadcastManager class,
public class BroadcastManager extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
String yourDate //must define
String yourHour //these two
Date d = new Date();
DateFormat date = new SimpleDateFormat("dd/MM/yyyy");
DateFormat hour = new SimpleDateFormat("HH:mm:ss");
if (date.equals(yourDate) && hour.equals(yourHour)){
Intent it = new Intent(context, MainActivity.class);
createNotification(context, it, "Time to refresh", "Take a Deep Breath", "It's time for your daily meditation");
}
}catch (Exception e){
Log.i("date","error == "+e.getMessage());
}
}
public void createNotification(Context context, Intent intent, CharSequence ticker, CharSequence title, CharSequence descricao){
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent p = PendingIntent.getActivity(context, 0, intent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setTicker(ticker);
builder.setContentTitle(title);
builder.setContentText(descricao);
builder.setSmallIcon(R.drawable.meditatebutton);
builder.setContentIntent(p);
Notification n = builder.build();
//create the notification
n.vibrate = new long[]{150, 300, 150, 400};
n.flags = Notification.FLAG_AUTO_CANCEL;
nm.notify(R.drawable.meditatebutton, n);
//create a vibration
try{
Uri som = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone toque = RingtoneManager.getRingtone(context, som);
toque.play();
}
catch(Exception e){}
}}
as you can see I must set your-date and your-hour variables whose values are in the TextViews that can be accessed by the main class only, How do I share these values among classes and solve this problem?
Ps- I'm implementing these classes according to this Set notification for specific date and time