pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Pebble JavaScript API
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AppFocusService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
    • Rocky
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Preferences
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

AppFocusService

Handling app focus The AppFocusService allows developers to be notified when their apps become visible on the screen. Common reasons your app may be running but not be on screen are: it's still in the middle of launching and being revealed by a system animation, or it is being covered by a system window such as a notification. This service is useful for apps that require a high degree of user interactivity, like a game where you'll want to pause when a notification covers your app window. It can be also used for apps that want to sync up an intro animation to the end of the system animation that occurs before your app is visible.

Function Documentation

void app_focus_service_subscribe_handlers(AppFocusHandlers handlers)

Subscribe to the focus event service. Once subscribed, the handlers get called every time the app gains or loses focus.

Parameters

handler

Handlers which will be called on will-focus and did-focus events.

See Also

AppFocusHandlers
void app_focus_service_subscribe(AppFocusHandler handler)

Subscribe to the focus event service. Once subscribed, the handler gets called every time the app focus changes.

Note

Calling this function is equivalent to

app_focus_service_subscribe_handlers((AppFocusHandlers){
  .will_focus = handler,
});

Out focus events are triggered when a modal window is about to open and cover the app.

In focus events are triggered when a modal window which is covering the app is about to close.

Parameters

handler

A callback to be called on will-focus events.

void app_focus_service_unsubscribe(void)

Unsubscribe from the focus event service. Once unsubscribed, the previously registered handlers will no longer be called.

Data Structure Documentation

struct AppFocusHandlers

There are two different focus events which take place when transitioning to and from an app being in focus. Below is an example of when these events will occur: 1) The app is launched. Once the system animation to the app has completed and the app is completely in focus, the did_focus handler is called with in_focus set to true. 2) A notification comes in and the animation to show the notification starts. The will_focus handler is called with in_focus set to false. 3) The animation completes and the notification is in focus, with the app being completely covered. The did_focus hander is called with in_focus set to false. 4) The notification is dismissed and the animation to return to the app starts. The will_focus handler is called with in_focus set to true. 5) The animation completes and the app is in focus. The did_focus handler is called with in_focus set to true.

Data Fields

AppFocusHandler will_focus

Handler which will be called right before an app will lose or gain focus.

Note

This will be called with in_focus set to true when a window which is covering the app is about to close and return focus to the app.

This will be called with in_focus set to false when a window which will cover the app is about to open, causing the app to lose focus.

AppFocusHandler did_focus

Handler which will be called when an animation finished which has put the app into focus or taken the app out of focus.

Note

This will be called with in_focus set to true when a window which was covering the app has closed and the app has gained focus.

This will be called with in_focus set to false when a window has opened which is now covering the app, causing the app to lose focus.

Typedef Documentation

typedef void(* AppFocusHandler)(bool in_focus)

Callback type for focus events.

Parameters

in_focus

True if the app is gaining focus, false otherwise.

Need some help?

Functions

  • app_focus_service_subscribe_handlers
  • app_focus_service_subscribe
  • app_focus_service_unsubscribe

Data Structures

  • AppFocusHandlers

Typedefs

  • AppFocusHandler

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!