Android I';我对安卓系统的服务感到困惑

Android I';我对安卓系统的服务感到困惑,android,android-service,android-alarms,Android,Android Service,Android Alarms,我有一个很大的程序,它有很多表单,可以处理数据库等。我的程序中有一个闹钟。当我在10-20秒后触发警报并清理内存(在任务管理器中)时,警报会触发一个事件(即使时间尚未到来)。如果我作为独立软件运行警报,它运行得非常完美 难道警报不能成为程序的一部分?或者问题出在哪里 这是我如何使用闹钟的: MY_Day=1; Intent myIntent = new Intent(MyService.this, MyAlarmService.class); pendingIntent

我有一个很大的程序,它有很多表单,可以处理数据库等。我的程序中有一个闹钟。当我在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();
}

重新考虑您的代码并阅读以了解有关服务的更多信息