0
많은 프로그램을 가지고 있으며 데이터베이스와 함께 작동하는 큰 프로그램이 있습니다. 내 프로그램의 일부로 알람이 있습니다. 10-20 초 후에 알람을 울리고 작업 관리자의 메모리를 청소하면 알람이 이벤트를 발생시킵니다 (시간이 아직 도착하지 않은 경우에도). 독립 소프트웨어로 알람을 실행하면 완벽하게 실행됩니다!Android에서 서비스에 대해 혼동스러워합니다.
알람이 프로그램의 일부가 될 수 없습니까? 아니면 문제가 될 수 있습니까?
이 내가 알람 작동하는 방법입니다
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();
}