Reputation: 4958
I want to create a service that has a onWindowFocusChanged method, native to Activity. but our client has requested the tablet to constantly be looking for such a change in focus is there a way to add such a listener to a service or have an activity run as part of the service?
Upvotes: 1
Views: 354
Reputation: 5116
Service does not have onWindowFocusChanged()
method.
But you can override onWindowFocusChanged()
in your Base Activity which is parent of all your activities and notify your Service by sending Intent to it:
Intent intent = new Intent("focus changed");
intent.setClass(this, MyService.class);
startService(intent);
You will receive the intent in the service via overriding onStartCommand(Intent intent, int flags, int startId)
method.
Upvotes: 1