I know there are many threads on Stackoverflow on this topic, and I have read each and every single one, but I am still very confused and am very sorry but I feel like I should post this.
When the application is run nothing really happens with the receivers, as if they are not receiving anything
My service:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int timerValue = pv.getTimerValues();
aCounter = new CountDownTimer((timerValue), 1000) { // set to
// timerValue
// later
public void onTick(long millisUntilFinished) {
int minutes, seconds;
String sSeconds, sMinutes, toSend;
seconds = (int) (millisUntilFinished / 1000) % 60;
minutes = (int) ((millisUntilFinished / (1000 * 60)) % 60);
sSeconds = Integer.toString(seconds);
sMinutes = Integer.toString(minutes);
toSend = (sMinutes + ":" + sSeconds);
sendMessage(toSend);
countDownCheck();
}
public void onFinish() {
MediaPlayer dingeffect = MediaPlayer.create(
getApplicationContext(), R.raw.timerfinished);
// mPlayer0.stop();
try {
dingeffect.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dingeffect.start();
// Intent intent2 = new Intent(ServiceTest.this, Meditate.class);
//startActivity(intent2);
sendMessage("finished");
}
};
aCounter.start();
return START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
private void sendMessage(String send) {
Intent intent1 = new Intent("countdowntimer");
// You can also include some extra data.
intent1.putExtra("message1", send);
sendBroadcast(intent1);
}
My receiving activity: Inside the onCreate:
registerReceiver(mMessageReceiver1, new IntentFilter("countdowntimer"));
final Intent countDownService = new Intent(Meditate2.this,
ServiceTest.class);
startService(countDownService);
and my broadcastreceiver inside the same activity
private BroadcastReceiver mMessageReceiver1 = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String message = intent.getStringExtra("message1");
setTimer(message);
}
};
In the manifest I have declared the service as such:
<service android:name=".ServiceTest"></service>
The weird thing is, it was working then after I fixed some other stuff this stopped working, so I really have no clue why it is not. Help please!