1

I have a perfectly functioning DreamService that I want to use within my main activity along with an extra button so that the user can access settings (Android TV appears to be missing the daydream settings icon as far as I can tell).

Is there an easy way this could be done that would specifically avoid duplication of code?

Remy
  • 1,414
  • 4
  • 20
  • 29

2 Answers2

1

Sure, just take the views you created for your service and put them in an activity instead. Make sure your views can work without a direct dependency on the service.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thanks for responding! This is what I suspected I would need to do... If I had a class containing all the code that updated the views, would I pass in all the individual view components from the Service and Activity? I tried fetching the views within an abstracted class before, but I recall it not working for some reason (it was a few weeks ago and my memory is appalling). Apologies for the noob-ish questions. :/ – Remy Mar 20 '16 at 22:00
  • If you're working with an Activity, you don't want to deal with the service at all. Just work with the views in a way that is natural for either component. – Doug Stevenson Mar 20 '16 at 22:05
0

You can invoke the DayDream like this -

Intent intentDream = new Intent(Intent.ACTION_MAIN);
intentDream.setClassName("com.android.systemui", "com.android.systemui.Somnambulator");
startActivity(intentDream);

Hope this helps.

Supratim Haldar
  • 2,376
  • 3
  • 16
  • 26