Quantcast
Channel: Show ProgressDialog and call OnBackPressed() after certain period - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Show ProgressDialog and call OnBackPressed() after certain period

$
0
0

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);

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>