Issue
The ProgressDialog should display for 5 secs after which OnBackPressed() should execute. Currently the ProgressDialog never appears on screen. If I put OnBackPressed() inside the delegate progress dialog is displayed but then I get error that OnBackPressed() should be executed from MainThread. What can I do?
private async SomeAsyncMethod()
{
await ShowProgressDialog();
......
}
private Task ShowMessage()
{
var progressDialog = ProgressDialog.Show(this, "Bestandskorrektur", "Bestandskorrektur wird ausgeführt! Bite warten...", true);
new Thread(new ThreadStart(delegate
{
Thread.Sleep(5000);
RunOnUiThread(() => progressDialog.Hide());
OnBackPressed(); // Gives error.
})).Start();
return Task.CompletedTask;
}
UPDATE: Solution based on answers:
var pd = ProgressDialog.Show(this, "Bestandskorrektur", "Bestandskorrektur wird ausgeführt! Bitte warten...", true);
var h = new Handler();
void action()
{
RunOnUiThread(() => pd.Hide());
OnBackPressed();
}
h.PostDelayed(action, 5000);
Solution
Try using a Handler().postDelayed() like below -
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//hide progressbar
onBackPressed();
}
}, 5000);
Answered By - darshan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.