-4

I have a service running in background and when some conditions are met I need to show a window at the top of the activity. I should be able to navigate between activities and that window should always stay static on top till the user dismiss it.

Options:

  1. I tried with an activity using Dialog Theme. The problem with this approach is that it will be on top of the activity that was at that instant. If I open another activity the "activity dialog" will be behind this new activity.

  2. I thought to implement a BaseActivity that has a frame layout in order to show this "window" every time you open a new Activity. The problem is that is being show again and it shouldn't, the window should be static meanwhile the activities are changing. Also not sure how to call transaction manager inside a service to add the fragment.

  3. I read something about having a Service that will attach a View on the Window Manager. The problem with this is that I am not sure if it's a good practice.

Any thoughts? Thanks!

Sol
  • 833
  • 1
  • 9
  • 17
  • https://www.androidhive.info/2016/11/android-floating-widget-like-facebook-chat-head/ – Vij Oct 12 '17 at 11:18
  • For this ill suggest you to use BaseActivity single activity application - get view in the top of activity just change that view when your service get data and other task work in fragment which is at bottom of activity just replace fragment it doesnt close your upper view of activity ....... – Sushant Gosavi Oct 12 '17 at 12:27

2 Answers2

1
I have one solution for that 

1. create a static variable in app 

public static Boolean isMatch=false ;

2. either create dialog  or layout that you have to show in activity and manage its show and hide.

2. Create Thread in activity and add 1000 timer


 Thread thread= new Thread() {

                        int wait = 0;

                        @RequiresApi(api = Build.VERSION_CODES.M)
                        @Override
                        public void run() {
                            super.run();

                                while (wait < welcomeScreenDisplay) {
                                    sleep(100);
                                   if(isMatch)
                                             {
                                       dialog.show();

                                      }
                                    wait += 100;

                                }
                        }//run
                    };//welcome thread
                    t.start();

3. in service when the condition is true update the value of the variable 


isMatch =true ;
Ravi Jat
  • 61
  • 1
  • 12
0

you can send a declare an explicit broadcast receiver for your app and once the service is done then automatically will send a message to the parent activity. In this activity you will have a view at the top with visibility gone, and once you receive the broadcast change the visibility