0

Trying to make something similar to facebook chat head. When we click on the chat head it opens up the chat. Now when we press back button it closes the popup of chat. How to capture onBackPressed event in a service?

Pranav Agrawal
  • 466
  • 6
  • 17

2 Answers2

1

This might work :

make the window or view you show via service as focusable, add a onKeylistener(for e.g. on rootview or other) and listen for KEYCODE_BACK.

jay shah
  • 903
  • 6
  • 21
  • made sure your view is focusable? only focusable views can recieve key events via keylistener. – jay shah Nov 30 '15 at 12:00
  • Activity.java in framework also does something similar, search for backpress, http://androidxref.com/6.0.0_r1/xref/frameworks/base/core/java/android/app/Activity.java, You must get key events on focused view to track Back. – jay shah Nov 30 '15 at 12:05
1

You can use this library here to make floating windows like facebook chat heads. This library's floating windows closes on back button press.

Eric B.
  • 4,622
  • 2
  • 18
  • 33