0

Imagine a "home screen" that runs a service. When the service reads bluetooth data that meets a certain value, it starts a new activity to notify the user of such a change.

What happens to the home screen activity when the new activity is created from the service? As far as I know, I cannot call finish() to end the activity from the service. I have to imagine that the home screen sits dormant somewhere in the stack?

What would happen if I ran this application all day and had 100 alerts?

for Example, from a service, I will call:

Intent alertActivity = new Intent(this, Alert.class);
alertActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(alertActivity);

Later, when the alert is cleared, it returns to the Home Screen.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Wouldn't it in this case be better to implement Notifications instead of a new Intent? Since you're only showing the data to user to notify him about the change?

Otherwise I think you could make a Callback method from Service to a method declared in Activity so it finnishes it.

cotnic
  • 158
  • 2
  • 11
  • This question was mostly theoretical. I'm making an emergency alert system that turns the user's phone on from a locked screen and makes their screen flash/vibrate (similar to setting an alarm at night). Administrators are able to clear the alerts. I'm not sure how to use callbacks! The above code is what I use in the services I use. Can you give me an example of such a callback to end an activity? I will look for myself in the meantime. –  Jul 21 '17 at 06:26
  • There was a answer about callback method on the following link: https://stackoverflow.com/questions/23586031/calling-activity-class-method-from-service-class – cotnic Jul 21 '17 at 06:28