SharonKats2469
Lurker
Hey i am use AlarmManager to start method every day at specific time, Everything work fine until i am close the app and waiting to AlaramMagaer to start method from activity (When the app open it's work but when i close the app the app crash) ,
This my code:
Activity
AlarmReceiver
I was try to different way to do it:
So i got the TOAST ("Alarm Set") but here the problem, if the app working so the method is start and work, But if i close the app and with to next day, In next day i got the TOAST("Alaram Set") but the method in the activity not start at all. We Taking about SMS_Next_Day(); method.
Some help?
This my code:
Activity
Code:
public ... OnCreate{
...
registerReceiver(broadcastReceiver, new IntentFilter("AUTO_SMS"));
...
}.............. Button
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 51);
calendar.set(Calendar.SECOND, 0);
AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarm.cancel(pendingIntent);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
SharedPreferences.Editor editor = getSharedPreferences("com.camel.work_list", MODE_PRIVATE).edit();
editor.putBoolean("AutoSMS", true);
editor.commit();
Toast.makeText(context, "Auto SMS is Enable", Toast.LENGTH_SHORT).show();
AlarmReceiver
I was try to different way to do it:
Code:
//First one
context.sendBroadcast(new Intent("AUTO_SMS"));
//Second try
Calendar_Activity a = Calendar_Activity.instance;
a.SMS_Next_Day();
//Checks System.out.println("checkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk");
Toast.makeText(context, "Alarm Set", Toast.LENGTH_SHORT).show();
So i got the TOAST ("Alarm Set") but here the problem, if the app working so the method is start and work, But if i close the app and with to next day, In next day i got the TOAST("Alaram Set") but the method in the activity not start at all. We Taking about SMS_Next_Day(); method.
Some help?
