Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
88 views
in Technique[技术] by (71.8m points)

java - Andriod chat-head not launching mainActivity

Please I have a chat-head bubble that pops up when onbackpress is called, but when I click on it, it doesn’t take me to the mainActivity.

This is the code, Please help me!!!!!!!!!!

private View chatHeadView;private WindowManager windowManager;    @Override    public IBinder onBind(Intent intent) { 
        return null;    } 
 
    @Override    public void onCreate() { 
        super.onCreate();        chatHeadView= LayoutInflater.from(this).inflate(R.layout.bubble_layout, null);        WindowManager.LayoutParams params= new WindowManager.LayoutParams( 
                WindowManager.LayoutParams.WRAP_CONTENT,                WindowManager.LayoutParams.WRAP_CONTENT,                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,                PixelFormat.TRANSLUCENT);        params.gravity= Gravity.TOP |Gravity.LEFT;        params.x=0;        params.y=100;        windowManager= (WindowManager) getSystemService(WINDOW_SERVICE);        windowManager.addView(chatHeadView,params);        RelativeLayout layout= chatHeadView.findViewById(R.id.chat_bubble_layout);        ImageView chatheadImage=chatHeadView.findViewById(R.id.avatar);        chatheadImage.setOnTouchListener(new View.OnTouchListener() { 
            private int initialX;            private int initialY;            private float touchY;            private float touchX;            private  int lastAction;            @Override            public boolean onTouch(View view, MotionEvent motionEvent) { 
 
                if(motionEvent.getAction()==MotionEvent.ACTION_DOWN){ 
                    initialX= params.x;                    initialY=params.y;                    touchX=motionEvent.getRawX();                    touchY=motionEvent.getRawY();                    lastAction= motionEvent.getAction();                } 
                if(motionEvent.getAction()==MotionEvent.ACTION_UP){ 
                    if(lastAction==MotionEvent.ACTION_DOWN){ 
                        Button button= new Button(ChatHeadService.this);                        button.setText("Open");                        RelativeLayout layout= chatHeadView.findViewById(R.id.chat_bubble_layout);                        layout.addView(button);                        button.setOnClickListener( 
                                new View.OnClickListener() { 
                                    @Override                                    public void onClick(View view) { 
//                                        Intent intent= new Intent(ChatHeadService.this, SplashActivity.class);                                        startActivity(intent);                                        windowManager.removeView(chatHeadView);                                    } 
                                } 
                        );                    } 
 
                lastAction=motionEvent.getAction();                return true;} 
                if(motionEvent.getAction()==MotionEvent.ACTION_MOVE){ 
                    params.x = initialX + (int) (motionEvent.getRawX()- touchX);                    params.y = initialY + (int) (motionEvent.getRawY()- touchY);                    windowManager.updateViewLayout(chatHeadView,params);                    lastAction= motionEvent.getAction();                    return true;                } 
                return true;            } 
 
        });    } 
 
 
    @Override    public void onDestroy() { 
        super.onDestroy();        if(chatHeadView!=null){ 
            windowManager.removeView(chatHeadView);        } 
    } 
 
} ```
question from:https://stackoverflow.com/questions/65831647/andriod-chat-head-not-launching-mainactivity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...