On LoginClick I want to run the user validation in the background while my ViewSwitcher switches over to the ProgressBar. I am having difficulty implementing the AsyncTask.
OnClick EventHander:
void LoginClick (Object o, EventArgs e)
{
_v.ShowNext ();
LoginUser lu = new LoginUser (this, _user.Text, _pw.Text);
lu.Execute ("run");
}
LoginUser Class:
class LoginUser: AsyncTask
{
private readonly string _userName;
private readonly string _password;
private readonly Context _context;
private User user;
public LoginUser (Context context, string userName, string password)
{
_context = context;
_userName = userName;
_password = password;
}
protected override Java.Lang.Object DoInBackground (Java.Lang.Object[] @params)
{
WS ws = new WS ();
user = ws.validateUser (_userName, _password);
return true;
}
protected override void OnPostExecute (Java.Lang.Object result)
{
Toast.MakeText (_context, user.Market, ToastLength.Long).Show ();
}
}
But when I build the project, I get a build error “LoginUser.DoInBackground is marked as an override but no suitable method found to override.”
UPDATE: So MonoDevelop is a little different in extending AsyncTask Class. Pretty much everywhere that I have my User class, I needed to put Java.Lang.Object. I can now build without any errors. However, now the app simply crashes immediately upon LoginClick.
E/mono (18020): Unhandled Exception: Java.Lang.NoClassDefFoundError: Exception of type 'Java.Lang.NoClassDefFoundError' was thrown.
E/mono (18020): at Android.Runtime.JNIEnv.FindClass (System.String classname) [0x00000] in <filename unknown>:0
E/mono (18020): at Android.Runtime.JNIEnv.FindClass (System.Type type) [0x00000] in <filename unknown>:0
E/mono (18020): --- End of managed exception stack trace ---
E/mono (18020): java.lang.NoClassDefFoundError: cpec_fm.LoginUser
E/mono (18020): at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
E/mono (18020): at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:29)
E/mono (18020): at android.view.View.performClick(View.java:3110)
E/mono (18020): at android.view.View$PerformClick.run(View.java:11934)
E/mono (18020): at android.os.Handler.handleCallback(Handler.java:587)
E/mono (18020): at android.os.Handler.dispatchMessage(Handler.java:92)
E/mono (18020): at android.os.Looper.loop(Looper.java:132)
E/mono (18020): at android.app.ActivityThread.main(ActivityThread.java:4143)
E/mono (18020): at java.lang.reflect.Method.invokeNative(Native Method)
E/mono (18020): at java.lang.reflect.Method.invoke(Method.java:491)
E/mono (18020):
Original Code Updated Above.
So just opened in Visual Studio and deployed and it works. So far have been very disappointed by MonoDevelop.