您好计算器
我试图开发可运行在特定的时间间隔某些任务的Android应用程序,我使用 AlarmManager
做任务时,code片断如下,
Hello stackoverflow
I'm trying to develop an android application that can run some task at specific time interval, I'm using AlarmManager
to do the task, the code snippet is as follows,
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();
}
}
问题是服务启动
信息将被显示在第一次当我点击单选按钮,但我想在服务启动
消息