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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…