dot42


Asynchronous SQLite sample with dot42?


I've been testing dot42 and so far great, but I see that there aren't any SQLite samples. Im not sure if I should implement a ContentProvider (as some android articles suggests) or if I could use the async / wait implementation of dot42 in order to perform a query asynchronously and show the result on a ListView.
Any advice ?
Thanks in advance
Roygar
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. ContactsDatabase inherits from SQLiteOpenHelper and implements the usual methods.
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<string> adapter;
ContactsDatabase database;
int i = 0;
protected override void OnCreate(Bundle savedInstance)
{
base.OnCreate(savedInstance);
SetContentView(R.Layouts.MainLayout);
ListView list = FindViewById<ListView>(R.Ids.list);
adapter = new ArrayAdapter<string>(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<Button>(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<Contact> contacts = null;
await Task.Factory.StartNew( () => {
// 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);
}
}
}
}

Related Links

Dot42 gives “object reference not set to an instance of an object” when inputting registration key
Get declared methods in interface
Referencing libraries from other solution
Emulator for Deploying and Debugging
Using native C libraries in dot42
Using SQLite with dot42
How to make a SOAP call with dot42?
How to handle “An Item with the same key has already been added” when adding .jar to dot42 project
How to unsubscribe an event with dot42
WaitOne() timeout parameter lost?
HOw do you uninstall Dot42
On every button click data is added to listview but in an unexpected manner . Data is repeated in the listview
Asynchronous SQLite sample with dot42?
dot42 - http POST request with parameters
Sharing code between a dot42 project and a mono desktop project

Categories

HOME
cygwin
alexa-skills-kit
toolbox
themes
camera
cakephp-3.4
vxml
emscripten
limit
ado.net
maxscript
zip
polling
crystal-reports-2013
nfs
opengl-es-3.0
tput
flash-player
altera
parameter-passing
entitymanager
chargify
wolframalpha
breadth-first-search
dataflow-diagram
google-cloud-print
panoramas
gitlab-api
mobx
python-2.6
complex-numbers
paragraph
dumpbin
android-sugarorm
biztalk-rule-engine
vue-chartjs
carriage-return
nested-lists
slacktextviewcontroller
release
health-monitoring
p4merge
dbnull
fwrite
geotiff
rserve
google-cse
wpas
webjars
parfor
lrs
vulcanize
windows-azure-queues
mta
vorpal.js
simevents
pre-build-event
deep
spreadjs
project-organization
upx
blitline
rasterize
custom-errors
atoi
mirror
ms-access-2000
fail2ban
deform
appserver
rcaller
malformedurlexception
dot42
terminate
vsx
code-duplication
oocss
facebook-timeline
http-status-code-410
twisted.web
booksleeve
idn
curb
frameworkelementfactory
midlet
xcode3.2
faye
correlated-subquery
azman
relative
screen-size
htdocs
rmdir
creole
luajava
objective-j
cldc
product-management
online-storage

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App