您好stackoverflow
我正在尝试开发一个可以在特定时间间隔运行某些任务的android应用程序,我正在使用AlarmManager
它来执行任务,代码片段如下,
if (radioBtnChecked)
{
MyActivity.this.alarmMgr = (AlarmManager) MyActivity.this.getSystemService(Context.ALARM_SERVICE);
Intent serviceIntent = new Intent(MyActivity.this, MyService.class);
MyActivity.this.pi = PendingIntent.getService(MyActivity.this, 0, serviceIntent, 0);
MyActivity.this.alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 10000, pi);
}//End of if condition
和MyService.java
public class MyService extends Service
{
@Override
public IBinder onBind(Intent intent)
{
return null;
}//End of onBind method
public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
Toast.makeText(getApplicationContext(),"Service started", Toast.LENGTH_SHORT).show();
}
}
问题是Service started
当我单击单选按钮时将首次显示该消息,但我希望该Service started
消息在10 seconds
. 请有人帮我解决这个问题,请分享您的知识,以便我纠正我的错误。
提前致谢。