Aaron Kapitsk
Aaron Kapitsk

Reputation: 21

How do I notify the "current" activity from a service or an alarm?

I am making an app that has 2 activities a service and an alarm.

How can I find the "current activity" from the service or the alarm ?

A) IE replace
Intent notificationIntent = new Intent(this, RatActivity.class);
with
Intent notificationIntent = new Intent(this, "CurrenActivity.class");

B) If an activity is visible tell it to look at a database if not visible put up a notification.

I have looked around quite a bit (including docs) and I still can't figure out.

Any help is appreciated.

Upvotes: 2

Views: 2871

Answers (1)

Phil Lello
Phil Lello

Reputation: 8639

This has pretty much been covered in Android: How can I get the current foreground activity (from a service)?

However, it might be simplest to toggle a value in SharedPreferences within the Activity onPause/onResume callbacks. See the Activity lifecycle docs for more info, specifically so you can cater for unexpected Activity termination.

Hope this helps,

Phil Lello

Upvotes: 1

Related Questions