私は多くの形式を持ち、データベースなどで動作する大きなプログラムを持っています。プログラムの一部としてアラームがあります。10〜20秒後にアラームを発生させて(タスクマネージャーで)メモリをクリーンアップすると、アラームはイベントを発生させます(時間がまだ到着していない場合でも)。独立したソフトウェアとしてアラームを実行すると、完璧に実行されます。
アラームをプログラムの一部にすることはできないのでしょうか?または、何が問題になる可能性がありますか?
これが私がアラームを操作する方法です:
MY_Day=1;
Intent myIntent = new Intent(MyService.this, MyAlarmService.class);
pendingIntent = PendingIntent.getService(MyService.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, MY_Houre);
cal.set(Calendar.MINUTE, MY_Minute);
cal.set(Calendar.SECOND, 0);
Total_Time = MY_Day * AlarmManager.INTERVAL_DAY;
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), Total_Time,
pendingIntent);
そしてこれは私のサービスです:
public class MyAlarmService extends Service {
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Toast toast = Toast.makeText(getApplicationContext(), "MyEvent", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout) toast.getView();
ImageView imageCodeProject = new ImageView(getApplicationContext());
imageCodeProject.setImageResource(R.drawable.koko);
toastView.addView(imageCodeProject, 0);
toast.show();
}