.net MAUI Android call StartActivityForResult synchronously and wait OnActivityResult is called #19603
Replies: 1 comment
-
Use of autoREsetEvent at viewmodel level it is working |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
from my application i need to create a new activity to an external app to retrieve a result in OnActivityResult .
It's working well with StartActivityForResult then OnActivityResult is raised after externalActivity finished to process... So caller code is already finished...
So i would like to call the parent method in my viewModel which execute the StartActivityForResult code in an async / await context to have a business code linear without using a callback in the OnActivityResult...
Actually
public class MyViewModel
{
public async OnCallExternalIntent()
{
androidService.CreateExternalIntent() => this method calls inside StartActivityForResult then running thread is leaving and StartActivityForResult is raised. It's working....
}
}
But I would like to execute the method CreateExternalIntent in an await context to retrieve StartActivityForResult like that
public class MyViewModel
{
public async OnCallExternalIntent()
{
var otherActivityResult = await androidService.CreateExternalIntent();
}
}
public Task CreateNewActivity()
{
StartActivityForResult(planeteMonetiqueIntent, transaction.InteropMessageId);
AutoResetEvent.WaitOne();
return Task.FromResult(_otherActivityResult);
}
I did this process to synchronized with USB device to retrieve Arduino process and my caller code is working well with await...
I saw this topic https://stackoverflow.com/questions/6351555/synchronous-startactivityforresult-waiting-for-activity-to-complete
I cannot use
Instrumentation instrumentation = new Instrumentation();
instrumentation.AddMonitor(planeteMonetiqueIntentFilter, null, false);
instrumentation.StartActivitySync(planeteMonetiqueIntent);
this code raised an error, cannot execute this code in main thread....
I tired to explain my probleme as simple as I can...
THank you.
Julien
Beta Was this translation helpful? Give feedback.
All reactions