title: How to send data to Android Wear TileService
body: <p>I don't really know, how to feed my Wear OS tiles with data. Currently, I am experimenting with receiving my heart rate from a BroadcastReceiver, which works but my value is always 0 inside onTileRequest.</p>
  <p>This is my TileService...</p>
  <pre class="lang-java prettyprint-override"><code>public class HeartRateTileService extends TileService {
      private static final String RESOURCES_VERSION = &quot;1&quot;;
  
      private String currentHeartrate = &quot;0&quot;;
  
      @Override          //onStartCommand never gets called
      public int onStartCommand(Intent intent, int flags, int startId) {
          int i = super.onStartCommand(intent, flags, startId);
          Log.d(&quot;HeartRate&quot;, &quot;onStartCommand &quot; + currentHeartrate);
          LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, new IntentFilter(&quot;heart-rate-to-activity&quot;));
          return i;
      }
  
      @Override
      public void onCreate() {
          super.onCreate();
          LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, new IntentFilter(&quot;heart-rate-to-activity&quot;));
      }
  
      @NonNull
      @Override
      protected ListenableFuture&lt;TileBuilders.Tile&gt; onTileRequest(
              @NonNull RequestBuilders.TileRequest requestParams
      ) {
          Log.d(&quot;HeartRate&quot;, &quot;onTileRequest &quot; + currentHeartrate);
          return Futures.immediateFuture(new TileBuilders.Tile.Builder()
                  .setResourcesVersion(RESOURCES_VERSION)
                  .setFreshnessIntervalMillis(1000*60)
                  .setTimeline(new TimelineBuilders.Timeline.Builder()
                          .addTimelineEntry(new TimelineBuilders.TimelineEntry.Builder()
                                  .setLayout(new LayoutElementBuilders.Layout.Builder()
                                          .setRoot(
                                                  layout()
                                          ).build()
                                  ).build()
                          ).build()
                  ).build()
          );
      }
  
      private LayoutElementBuilders.LayoutElement layout() {
          return new LayoutElementBuilders.Row.Builder()
                  .setWidth(wrap())
                  .setHeight(expand())
                  .setVerticalAlignment(LayoutElementBuilders.VERTICAL_ALIGN_CENTER)
                  .addContent(new LayoutElementBuilders.Text.Builder()
                          .setText(currentHeartrate)
                          .build()
                  ).build();
      }
  
      @NonNull
      @Override
      protected ListenableFuture&lt;ResourceBuilders.Resources&gt; onResourcesRequest(
              @NonNull RequestBuilders.ResourcesRequest requestParams
      ) {
          Log.d(&quot;HeartRate&quot;, &quot;onResourcesRequest &quot; + currentHeartrate);
          return Futures.immediateFuture(new ResourceBuilders.Resources.Builder()
                  .setVersion(RESOURCES_VERSION)
                  .build()
          );
      }
  
      private final BroadcastReceiver messageReceiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
              Log.d(&quot;HeartRate&quot;, &quot;message: &quot; + currentHeartrate);
              currentHeartrate = intent.getExtras().getString(&quot;message&quot;);
          }
      };
  
  }
  
  </code></pre>
  <p>This is what I get...
  As you see onTileRequest is always 0. Maybe it's because onCreate gets called too whenever onTileRequest gets called and therefore my data is 0 at this moment. But how can I save the heart rate permanently then? Am I doing something wrong? Or are tiles just not meant to receive data of a BroadcastReceiver. Are there other ways? I literally found nothing about updating tiles with data on the internet.</p>
  <pre><code>I/OpenGLRenderer: Initialized EGL, version 1.4
  D/OpenGLRenderer: Swap behavior 2
  D/HeartRate: onCreate 0
  W/t.myapplicatio: Accessing hidden field Ljava/nio/Buffer;-&gt;address:J (light greylist, reflection)
  D/HeartRate: onTileRequest 0
  D/HeartRate: onResourcesRequest 0
  D/ViewRootImpl[MainActivity]: changeCanvasOpacity: opaque=false
  D/HeartRate: onCreate 0
  D/HeartRate: message: 0
  D/HeartRate: message: 0
  D/HeartRate: message: 81
  D/HeartRate: message: 81
  D/HeartRate: onCreate 0
  D/HeartRate: message: 81
      message: 81
      message: 0
  D/HeartRate: message: 81
  I/chatty: uid=10096(com.pezcraft.myapplication) identical 1 line
  D/HeartRate: message: 82
  D/HeartRate: message: 72
  I/chatty: uid=10096(com.pezcraft.myapplication) identical 1 line
  D/HeartRate: message: 72
  D/HeartRate: message: 73
  I/chatty: uid=10096(com.pezcraft.myapplication) identical 1 line
  D/HeartRate: message: 73
  D/HeartRate: onCreate 0
  D/HeartRate: onTileRequest 0
  D/HeartRate: message: 75
  I/chatty: uid=10096(com.pezcraft.myapplication) identical 1 line
  D/HeartRate: message: 75
      message: 0
  D/HeartRate: message: 75
  I/chatty: uid=10096(com.pezcraft.myapplication) identical 2 lines
  D/HeartRate: message: 75
  </code></pre>