开发者

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜