gpt4 book ai didi

android - AlarmService示例错误构建找不到AlarmService_Service.class

转载 作者:行者123 更新时间:2023-11-29 02:14:37 26 4
gpt4 key购买 nike

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();
}
};
}

最佳答案

您在 Intent 中引用了 AlarmService_Service.class。执行此 android 需要源代码中的 AlarmService_Service 类。我认为该类不在您的代码中。

您有 2 个选项,要么定义 Activity AlarmService_Service(也在 list 中定义引用),要么引用此链接 http://android-er.blogspot.com/2010/10/simple-example-of-alarm-service-using.html

这应该可行

关于android - AlarmService示例错误构建找不到AlarmService_Service.class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5051840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com