Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a code sample that retrieves contacts from a SQLite database asynchronously using the async/await implementation of dot42. I omitted the SQLite code. <code>ContactsDatabase</code> inherits from <code>SQLiteOpenHelper</code> and implements the usual methods.</p> <pre><code>using System; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using Android.App; using Android.Os; using Android.Widget; using Dot42; using Dot42.Manifest; [assembly: Application("SQLiteAsyncSample")] namespace SQLiteAsyncSample { [Activity] public class MainActivity : Activity { private ArrayAdapter&lt;string&gt; adapter; ContactsDatabase database; int i = 0; protected override void OnCreate(Bundle savedInstance) { base.OnCreate(savedInstance); SetContentView(R.Layouts.MainLayout); ListView list = FindViewById&lt;ListView&gt;(R.Ids.list); adapter = new ArrayAdapter&lt;string&gt;(this, Android.R.Layout.Simple_list_item_1); list.SetAdapter(adapter); database = new ContactsDatabase(this); database.AddContact(new Contact("Frank", "012")); database.AddContact(new Contact("Marco", "345")); database.AddContact(new Contact("Hans", "678")); database.AddContact(new Contact("Sergey", "901")); Button addAllButton = FindViewById&lt;Button&gt;(R.Ids.showall); addAllButton.Click += showAllButton_Click; // Set the static synchronization context to the current/latest 'this'. // This allows the code after the wait to resume on the 'current' this // even if the Activity was recycled, e.g. due to a device rotation. SynchronizationContext.SetSynchronizationContext(this); } private async void showAllButton_Click(object sender, EventArgs e) { List&lt;Contact&gt; contacts = null; await Task.Factory.StartNew( () =&gt; { // lengthy job contacts = database.GetAllContacts(); }).ConfigureAwait(this); // make sure to access the adapter from the UI thread // so not in the anonymous delegate above foreach (Contact contact in contacts) { adapter.Add(contact.Name); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload