2

AlarmService サンプル エラー ビルドで AlarmService_Service.class が見つかりません。私は何が欠けていますか?

コード:

public class AlarmService extends Activity {
  private PendingIntent mAlarmSender;

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Create an IntentSender that will launch our service, to be scheduled
    // with the alarm manager.
    mAlarmSender = PendingIntent.getService(AlarmService.this, 0,
        new Intent(AlarmService.this, AlarmService_Service.class), 0);
    setContentView(R.layout.main);
    // Watch for button clicks.
    Button button = (Button) findViewById(R.id.Button01);
    button.setOnClickListener(mStartAlarmListener);
    button = (Button) findViewById(R.id.Button02);
    button.setOnClickListener(mStopAlarmListener);
  }

  private OnClickListener mStartAlarmListener = new OnClickListener() {

    public void onClick(View v) {
      // We want the alarm to go off 30 seconds from now.
      long firstTime = SystemClock.elapsedRealtime();
      // Schedule the alarm!
      AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
      am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime,
          3 * 1000, mAlarmSender);
      // Tell the user about what we did.
      Toast.makeText(AlarmService.this, "Repeating Scheduled",
          Toast.LENGTH_LONG).show();
    }
  };
  private OnClickListener mStopAlarmListener = new OnClickListener() {

    public void onClick(View v) {
      // And cancel the alarm.
      AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
      am.cancel(mAlarmSender);
      // Tell the user about what we did.
      Toast.makeText(AlarmService.this, "Repeating Unscheduled",
          Toast.LENGTH_LONG).show();
    }
  };
}
4

1 に答える 1

1

インテントで AlarmService_Service.class を参照しました。この android を実行すると、ソース コードに AlarmService_Service クラスが必要になります。そのクラスはあなたのコードにないと思います。

Activity AlarmService_Service を定義する (マニフェストで参照も定義する) か、このリンクを参照するかの 2 つのオプションがありますhttp://android-er.blogspot.com/2010/10/simple-example-of-alarm-service -using.html

これはうまくいくはずです

于 2011-02-19T16:51:38.327 に答える