Question

We start with an activity that starts a service then becomes idle until the service calls the activity again. the activity goes to onPause(i believe) and isn't started back up until the its BroadcastReceiver gets its call to start. My service creates a WindowManager as a system overlay and when the user triggers it, it is supposed to call the activity and make the activity make a new view with some stuff in it. Well everything goes through without a hitch, no errors popup and all my logs suggest that the code runs through smoothly, but the new view that is supposed to be made never comes to view. Interestingly enough though, if you click the app to start it again, up pops the view i wanted earlier. so I'm curious as to why it doesn't happen when i want it to, but instead it remains invisible. I've tried setting the view to visible, tried bringToFront(), and i even tried some flags on the intent to bring the activity to the top of the stack but none of those work. relevant code is below.

im not here to hear about why you don't think my app is good for the user or that you don't think it follows androids base "design" i just want help debugging this interesting bug.

MainActivity

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = new Intent(MainActivity.this, MyService.class);
        startService(intent); //if i comment out these lines and add the call
        initService(); //to figureOutParam below it works perfectly
        sendUserHome(); //this one as well
        figureOutParam("UPDATE",0); //this is the call that i use to get through to
                         //the method though right now neither param is important
    }


    public void figureOutParam(String param, int top){

        if(param.equals("UPDATE")){

            View myView = new View(this);

            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            myView = inflater.inflate(R.layout.activity_main, null);
            myView.setBackgroundColor(Color.BLUE);
            myView.bringToFront();

            setContentView(myView);
        }
    }

MyService (only important part involving the call back to service)

 @Override
    public void onCreate() {
        super.onCreate();

        WindowManager window = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
        Display d = window.getDefaultDisplay();
        int width=d.getWidth();
        int height=d.getHeight();
        height= (int)(height*.025);


        params = new WindowManager.LayoutParams(WindowManager.LayoutParams.FILL_PARENT,height,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | 
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, 
                PixelFormat.TRANSLUCENT);
        params.gravity=Gravity.BOTTOM;
    wm = (WindowManager) getSystemService(WINDOW_SERVICE);

    }

    public void updateView(String params){
            Intent i = new Intent(MY_INTENT);
            i.putExtra("y", this.y);
            i.putExtra("param", params);
            sendBroadcast(i);
        }

Manifest because, well because

No correct solution

OTHER TIPS

Try to inserting the figureOutParam("UPDATE",0); after the super.onCreate(savedInstanceState);.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top