title: Send platform message to Android method from background flutter isolate
body: <p>I want to have a dart background service running forever (isolates) which will communicate with a server through websockets. And I have an API for Android which gather information to send to the server. 
  How can I invoke that Android methods which use callbacks and everything from the background isolate?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>So far in dart I created an Isolate to periodically invoke the poolSong method in background even if the user is using another app or has the screen turned off.</p>
  
  <p>But that gives me the error below...on the github issues they say that I can't send a platform message from a different Isolate unless it's the main. But if I do it from the main isolate, when the user exit the app that isolate will terminate too.</p>
  
  <h3>MainDart</h3>
  
  <pre><code>class _MyHomePageState extends State&lt;MyHomePage&gt; {
      final GlobalKey&lt;ScaffoldState&gt; scaffoldKey = new GlobalKey&lt;ScaffoldState&gt;();
      static const platform = const MethodChannel('mainService');
  
      static _poolSong(SendPort sendPort) async {
          const oneSec = const Duration(seconds:1);
          new Timer.periodic(oneSec, (Timer t) =&gt; platform.invokeMethod('poolSong'));
      }
  
      @override
      void initState() {
          super.initState();
          ReceivePort receivePort = ReceivePort();
          Isolate.spawn(_poolSong, receivePort.sendPort);
      }
          ·
          ·
          ·
  </code></pre>
  
  <h3>MainActivityJava</h3>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      GeneratedPluginRegistrant.registerWith(this);
  
      new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
          (call, result) -&gt; {
              if (call.method.equals("startService"))
                  startService();
              if (call.method.equals("poolSong"))
                  poolSong();
          }
      );
  }
  </code></pre>
  
  <h3>ERROR</h3>
  
  <pre><code>E/flutter (25412): [ERROR:flutter/runtime/dart_isolate.cc(717)] Isolate (765499726) 'main.dart:_poolSong()' exited with an error
  E/flutter (25412): [ERROR:flutter/shell/common/shell.cc(186)] Dart Error: Unhandled exception:
  E/flutter (25412): error: native function 'Window_sendPlatformMessage' (4 arguments) cannot be found
  E/flutter (25412): #0   Window.sendPlatformMessage (dart:ui/window.dart:811:9)
  E/flutter (25412): #1   BinaryMessages._sendPlatformMessage (package:flutter/src/services/platform_messages.dart:39:15)
  E/flutter (25412): #2   BinaryMessages.send (package:flutter/src/services/platform_messages.dart:87:12)
  E/flutter (25412): #3   MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:286:49)
  E/flutter (25412): &lt;asynchronous suspension&gt;
  E/flutter (25412): #4   _MyHomePageState._poolSong.&lt;anonymous closure&gt; (package:musictie/main.dart:37:54)
  E/flutter (25412): #5   _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
  E/flutter (25412): #6   _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
  E/flutter (25412): #7   _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
  </code></pre>