There’s broadcastReceiver receive boot message and set a alarmmanager.
It start a service every DELAY mins:
Intent intent = new Intent();
intent.setAction("org.jxdwinter.getMessageServcie");
PendingIntent pendingintent = PendingIntent.getService(arg0, 0, intent, 0);
am = (AlarmManager) arg0.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), DELAY, pendingintent);
The service poll data from romate server in a new thread:
public int onStartCommand(Intent intent, int flags, int startId)
{
this.getMessage.start();
return Service.START_NOT_STICKY;
}
private class GetMessage extends Thread
{
public void run()
{
... ....
}
}
And when the app started, I can get the data at very first time and there’s no
error.
Then the service start again in DELAY mins , there’s an error:Thread already started.
Why is happened? Pls help me with this. Thank you!
Maybe you could just create a new instance of your thread each time you need it to run: