2

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.

Aaron Kapitsk
  • 21
  • 1
  • 3

1 Answers1

1

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

Community
  • 1
  • 1
Phil Lello
  • 8,377
  • 2
  • 25
  • 34