0

I have a Xamarin forms Android app that is running without problems. It consists of a foreground app that is used for configuration purposes and a background thread that listens for events. Everything works great and as expected.

I was asked to add an enhancement. When the background thread receives a specific event, I need to launch another app installed on the device. I have coded this, and it works... sort of. The external app is only launched if the main thread is in the foreground. What I need to do is either find a way of starting a NEW intent that launches the app from the background thread, or to have the background thread push the main thread back into the foreground? Either way will work, the second method is a workaround... but the app currently works under those conditions.

Any other

stewbash
  • 51
  • 6
  • You mean that you want to run some code on MainThread? If yes, you can using [Xamarin.Essentials: MainThread](https://learn.microsoft.com/en-us/xamarin/essentials/main-thread#running-code-on-the-main-thread) – Cherry Bu - MSFT Aug 03 '21 at 03:04

1 Answers1

0

You can run code in the MainThread with

MainThread.BeginInvokeOnMainThread(() =>
{
    //Your Code here
});
Kajot
  • 1,043
  • 2
  • 15
  • 22
  • Although this seems to work, in my case "MainThread" is the primary application that is no longer in the foreground. I need to bring the MainThread back into the foreground. – stewbash Aug 04 '21 at 05:23
  • @Kajot Seems that you want to bring your app to foreground, maybe you can take a look [Foreground Services](https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/services/foreground-services) – Cherry Bu - MSFT Aug 06 '21 at 06:46