I have an ImageView in my activity that shows an “active” symbol when a service is activated.
After the Service has been executed the ImageView should go back to the “inactive” Symbol.
AlarManager that starts Service:
context = this;
Intent intent = new Intent(context, AlarmReceiver.class);
sender = PendingIntent.getBroadcast(context, INTENT_CODE, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calNew.getTimeInMillis(), sender);
setImage(active);
AlarmManager:
@Override
public void onReceive(Context context, Intent intent) {
Intent wakeupIntent = new Intent(context, WakeupActivity.class);
context.startService(wakeupIntent);
}
How can I make the Image change back to inactive after the service has been executed? I tried to create a new Runnable and then postDelayed(runnable, calNew.getTimeInMillis()) using a handler. Actually it didn’t work, nothing happened. Is there a better way to do this?
Step #1: Add the Android Support package to your application.
Step #2: Have your activity register a
BroadcastReceiverwithLocalBroadcastManagerinonResume()and unregister it inonPause().Step #3: Have your service send a broadcast via
LocalBroadcastManagerwhen its work is complete, to be picked up by the activity’sBroadcastReceiver.Here is a sample project demonstrating this technique.