Issue
I need to implement the logic - If user on chat activity then I don't need to show push notification with new message. So I need to know what activity is on the screen. For this purpose I found this answer How to get current foreground activity context in android? But I don't understand how to use
public void registerActivityLifecycleCallbacks (Application.ActivityLifecycleCallbacks callback)
Can some one give me a full example how to discover what activity is on screen?
Solution
You have to implement onActivityPaused
and onActivityResumed()
public class YourApplication extends Application implements
Application.ActivityLifecycleCallbacks {
public static boolean isChatVisible=false;
public void onCreate() {
super.onCreate();
registerActivityLifecycleCallbacks(this);
}
@Override
public void onActivityCreated(Activity p0, Bundle p1) {
}
@Override
public void onActivityStarted(Activity p0) {
}
@Override
public void onActivityResumed(Activity p0) {
isChatVisible=p0 instanceof ChatActivity;
}
@Override
public void onActivityPaused(Activity p0) {
}
@Override
public void onActivityStopped(Activity p0) {
}
}
Before building the notification just check YourApplication.isChatVisible()
Answered By - Rajasekaran M
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.