我正在使用一个非常好的IntentService来完成一些后台任务。在我的应用程序的其他部分使用AsinkTasks进行简短操作,但如果我启动AsyncTask(在IntentService完成其工作之后),则不会调用doInBackground和OnPostExecute。部分代码:
IntentService:
public class MyService extends IntentService{
@Override
public void onCreate() {
super.onCreate();
...
...
}
@Override
protected void onHandleIntent(Intent intent) {
...
...
...
}
}
的AsyncTask
private void caricaNomeAvatar() {
new AsyncTask<String, Void, String>() {
String nome = null;
String foto = null;
@Override
protected String doInBackground(String... urls) {
Log.d("doInBackground", "doInBackground");
nome = UT_drive_dropbox.AM.getNomeEcognome();
foto = UT_drive_dropbox.AM.getfoto();
return null;
}
@Override
public void onPostExecute(String result) {
Log.d("onPostExecute", "onPostExecute");
super.onPostExecute(result);
if (foto != null) {
new LoadAvatar(imgFoto).execute(foto);
} else {
finishAffinity();
Intent inte = new Intent(Drive_login.this, Menu_drawer_pro.class);
inte.putExtra("sync", true);
startActivity(inte);
}
}
}.execute();
}
调用方法:
@Override
public void onConnOK() {
caricaNomeAvatar();
}