I need to change my LoginMechanism into an asynchTask, so that it wont throw a android.os.NetworkOnMainThreadException in SDK 4.x. Its not clear for me how I can start a new intent in this asynctask. I understand that the work will be done in the doInBackground-Method and this return result will be processed in the onPostExecute method. In this method I tried to start my new activity and my service but it shows me compiler errors
The constructor Intent(MainActivity.LoginTask, Class<AttachService>) is undefined
and here is the onPostExecute Method
@Override
protected void onPostExecute(String result) {
super.onPostExecute( result );
if (result.equals("")){
loginError.setText(R.string.login_error);
loginError.setVisibility(View.VISIBLE);
}
else{
loginError.setVisibility(View.INVISIBLE);
startService(new Intent(LoginTask.this, AttachService.class));
Log.d(TAG, "setting status of user " + login.getText().toString() + " to stored for service endpoint " + service_endpoint_spinner.getSelectedItemId());
if (appData.getLoggedInUser() == null){
loggedInUser = DBManager.getInstance().storeUser(user,hashedPw,target, true);
appData.setLoggedInUser(loggedInUser);
DBManager.getInstance().setUserStatusToStored(loggedInUser);
}
startActivity(new Intent(this, ActionActivity.class));
}
}
All the startservice and startActivity methods produces compiler error, can someone explain why. Thanks